Creating An Object
✏ Beginners Scripting Guide ✏
In this section, we will be discussing about how to create object. To create object in Roblox, we will have to use the Instance
data type that hold a constructor that allows us to create an object with it class name.
CREATING THE OBJECT
First we will make a variable and call out the new()
constructor from the Instance data type to create an object, and then pass in the object type. Our object is a part so we do this:
local myPart = Instance.new('Part')
CHANGING THE PART PROPERTIES
Now we will change the part properties by index out the property name by using .
and change it by assign it a data.
local myPart = Instance.new('Part')
myPart.Name = 'MyPart' -- Set name to MyPart.
myPart.BrickColor = BrickColor.Red() -- Set part color to red.
myPart.Anchored = true -- Set the part Anchored to true to make it not fall.
myPart.CanCollide = true -- Set the part CanCollide to true to make it not go through baseplate when it fall for some reason.
myPart.Position = Vector3.new(0, 5, 0) -- Setting the part position.
myPart.Parent = workspace -- Parent the part into the workspace. To make it easier to understand it basically put the part in the workspace.
Last updated