Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Would Instance.new create multiplt objects if called more than once?

Asked by
Notwal 2
7 years ago

Would this script create ten string values or one?

local listofobjects = {
    ["owner"] = Instance.new("StringValue");
    ["type"] = Instance.new("StringValue");
    ["level"] = Instance.new("IntValue");
    ["health"] = Instance.new("IntValue");
}

for i = 1, 10 do 
    listofobjects["owner"].Parent = <idk somewhere random>
end


0
It would create one string object and move it around ten times. You could, however clone the object in the loop and parent the clone where you want to make ten string objects. GoldenPhysics 474 — 7y

1 answer

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

This would not work because there is only one of said Instance. The way I would get around this is by cloning the Instance and then moving it to wherever you'd like to

Here is my script:

local listofobjects = {
    ["owner"] = Instance.new("StringValue");
    ["type"] = Instance.new("StringValue");
    ["level"] = Instance.new("IntValue");
    ["health"] = Instance.new("IntValue");
}

for i,v in pairs (listofobjects) do 
    for num= 1, 10 do
        local obj = v:clone()
        obj.Parent = workspace
    end 
end

Using a for loop in tables will provide two values. The 'i' will provide the name of the variable, and the 'v' will provide what the variable is equal to

As you can see, it clones each Instance 10 times and puts them into workspace.

2
You might want to comment your code, so he knows what each bit is doing. RemasteredBox 85 — 7y
0
That code is pretty explanatory. Link150 1355 — 7y
Ad

Answer this question