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

How do i set how much Instance i want Instance.new to generate?

Asked by 5 years ago

So for example Lets say I did Instance.new('Part') But i wanted it to do it 100 times what would I have to do is there a parameter? also this has to be done instantly not with a loop

0
I don't think that exist, you could just Clone() it 10 times tho. MArzalAlBuchariZ 33 — 5y

2 answers

Log in to vote
0
Answered by
HaveASip 494 Moderation Voter
5 years ago
Edited 5 years ago

You can't set instance count, but you can create a lot of instances in couple of lines using "for loop".

For example:

local CountOfInstances = 10 -- this is the count, how much instances you will  create

for i = 1,CountOfInstances do
    local Part = Instance.new("Part")
    Part.Parent = workspace
    Part.Name = "Part_".. i
    wait()
end

P.S.

Sorry for my bad English ;p

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Unfortunately unless you want to write 100 separate lines for each part using:

local part00 = Instance.new("Part")
local part01 = Instance.new("Part")
-- etc.

then the most efficient way to do this is a for-loop, which you can set without a wait-time (though this isn't recommended) which can be used to generate the exact same part 100 times:

for i = 1, 100, 1 do
    local part = Instance.new("Part")
    part.Parent = workspace
end

The above loop has parameters set as the (starting number, ending number, increment)

Answer this question