Instance.new||doc136403

September 20, 2022

Format

Instance.new(className, parent, params)

Describe

Create an instance object of a specific type. If the parent is not passed during creation, the returned object only exists in memory, and the instance will only run and render in the scene. If you need to generate an instance in advance, you can pass the parent first, and then set it to the scene when you need it. middle. The purpose of the initialization parameter is to set the corresponding property value to the instance object after the instance is created.

The types of instances that can be created are:

Part Decal Folder WeldConstraint

parameter

Variable name Type Describe
className string Type name
parent Instance Parent, can't pass
params table<string, variant> Initialization parameters, not required

Return value

Type Describe
Instance Instance object

Code example

The server creates an anchored base part scaled to (5, 5, 5) at the scene map001 at coordinates (1, 1, 1)

local map = World:GetStaticMap("map001")
Instance.new("Part", map.Root, {
    WorldPosition = Vector3.new(1,1,1),
    WorldScale = Vector3.new(5,5,5),
    Anchored = true
})

Initialization parameters example

local map = World:GetStaticMap("map001")
local part = Instance.new("Part", map.Root)
part.WorldPosition = Vector3.new(0,2,0)
part.WorldScale = Vector3.new(5,5,5)
part.Anchored = true

Equivalent to

local map = World:GetStaticMap("map001")
local part = Instance.new("Part", map.Root, {
    WorldPosition = Vector3.new(1,1,1),
    WorldScale = Vector3.new(5,5,5),
    Anchored = true
})