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

How to make infinite clones?

Okay so I have a part that drops clones of a part that does damage. But I need an infinite amount of clones, because I need to copy and paste this block over a few times

But what my script does is drop a part, then pick it back up and drop it again, but this doesn't work with many parts

Here's the script:

rock = workspace.Fallen:Clone()
pos = script.Parent

while true do
	wait(math.random(2,4))
	rock.Parent = workspace
	rock.Position = pos.Position 
	
end

2 answers

✓ Accepted answer

Since 'rock' is assigned to workspace.Fallen:Clone() only, it would make sense that the part is re-positioned to the position of 'pos'.

'rock' is only referring to the cloned version of workspace.Fallen and nothing else. The 'while' loop doesn't create more, it is only using the same old 'rock', not making new clones.

Just reposition your 'rock' variable after the wait(math.random(2,4)) method:

pos = script.Parent

while true do
	wait(math.random(2,4))
	rock = workspace.Fallen:Clone()	-- This will clone and re-position that clone every 2-4 seconds(with a new clone, of course)
	rock.Parent = workspace
	rock.Position = pos.Position 
end

Compare the aforementioned code from this:

rock = workspace.Fallen:Clone()	-- This is cloning 'workspace.Fallen'.
pos = script.Parent

while true do
	wait(math.random(2,4))
	rock.Parent = workspace		-- This will set the parent of 'workspace.Fallen's' same old clone
	rock.Position = pos.Position 	-- This will re-position the same old clone of 'rock'
end

You need to create a local clone each time it does this. Before the script was using the same clone just positioning it over and over again. Here is an example:

pos = script.Parent

while true do
    wait(math.random(2,4))
    local rock = workspace.Fallen:Clone()
    rock.Parent = workspace
    rock.Position = pos.Position 

end

Now it should create a new clone stored in a variable then you can do whatever you want to this variable and because it is local it will create a new one every time you loop!

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