A game would be very limited if you could not add in new objects during a game. To script in a new part, use the following:
local part = Instance.new("Part")
part.Parent = game.Workspace
‘Instance‘ is the name of a special base-level class that most other Roblox classes are built atop. Instance cannot be created in a script but instead, used to construct new instances of objects.
This is done so by calling its ‘constructor.’ The constructor is a special type of method that “initializes” and creates the object.
The constructor name you will most often encounter is ‘new‘ but other classes and datatypes might also have additional constructors with different names.
In this case, you are constructing a new instance of the class “Part.”
Unlike with most other methods, which are called using the colon, constructors are called via the dot operator and returns some Roblox instance or datatype.
If all of these terms feel overwhelming right now, do not stress. At this stage, it’s mostly unimportant and you will intuit their usage as you gain experience.
Later on when we get to object-oriented programming, we will go over these concepts in more detail.
To delete a part, call its ‘Destroy‘ method:
local part = Instance.new("Part")
part.Parent = game.Workspace
part:Destroy()