for i = 1,50 do wait() clone = script.Parent:Clone() clone.Parent = workspace clone.Position = Vector3.new(-3,5,math.random(-209,-201)) clone.Rotation = Vector3.new(math.random(0,180),0,-0) end
I thought i = 1,50 do
means it will run 50 times, but it clones over 2,000 times. (Not even exaggerating i selected all the parts and it said 2000+).
GIF: http://gyazo.com/62785aacac6da230ba9147f8bf5a5108
End: http://gyazo.com/21f388ffeb7ada24afe902bda960ccb1
BrickCount(1.8K): http://gyazo.com/a3659c4e4985095a57ec36ad0c67fe8d
The reason it's cloning over 50 times is because you're cloning the scripts parent, which will house a clone of the script and will run that 50 times too.
To fix this, you need to disable the script inside the clone in your loop by doing clone[script.Name].Disabled = true
, which will disable the script inside the clone. You could also destroy the clone's script, which I personally believe would be the better option.
Overall, the final code will look like this:
for i = 1,50 do wait() clone = script.Parent:Clone() clone[script.Name]:Destroy() clone.Parent = workspace clone.Position = Vector3.new(-3,5,math.random(-209,-201)) clone.Rotation = Vector3.new(math.random(0,180),0,-0) end
EDIT: You could also set the Archivable property of the script to false as suggested by duckwit as the script is then ignored when calling Clone on the part.
Use a repeat + variable. Here:
Parts = 0 repeat wait() local Clone = script.Parent:Clone() Clone.Parent = game.Workspace Clone.Position = Vector3.new(-3, 5, math.random(-209, -201)) Clone.Rotation = Vector3.new(math.random(0, 180), 0, 0) until Parts = 50