PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Anchor a Part using Code

Anchor a Part using Code

Jun 23 2018, 2:02 AM PST

Problem

Create a part that stays stationary (anchored in place).

Solution

Use the Instance.new() function, the Anchored property, and the Parent property.

local part = Instance.new('Part')
part.Anchored = true
part.Parent = workspace

Discussion

To create an instance of a Roblox object (the things that can be manipulated in your game, like a block), you must use the Instance.new() function. This function is used to create all Roblox objects. It returns the object which is then assigned to the variable part.

There are two properties (a property is a characteristic of an object) that are changed afterwards:

  1. The goal states that this part should be stationary, meaning that it should not fall to the ground. In order to do so, the Anchored property should be set to true.

  2. In order for a part to appear in the game, its Parent property must be set to a directory called Workspace. This can be accessed by writing game.Workspace or simply Workspace.

Tags:
  • anchor
  • part