Beginners Scripting Guide (BETA)
  • Getting Started
  • Basic Data Types
  • Variables
  • Basic global functions
  • Number Arithmetic & Compounds Assignment
  • If statement
  • Function
  • Table & Dictionary
  • Loops
  • Creating An Object
  • Understanding Client & Server
  • RemoteEvent
  • Unfinished & In-progress
    • Methods
    • RemoteFunction
    • Basic libraries
    • Basic Services
    • Basic of Vector3 and CFrame
    • Basic built-in events
Powered by GitBook
On this page

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.

Class name is basically the object type that you want to create. And constructor is a special type of function that we can call it to create an object.

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.
PreviousLoopsNextUnderstanding Client & Server

Last updated 11 months ago