Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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


1 comment

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.

1 answer

✓ Accepted answer

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 comments

2

You might want to comment your code, so he knows what each bit is doing.

0

That code is pretty explanatory.

This discussion is preserved as it was. New answers, comments, and votes are closed.