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

Using a for loop, how do I make a part move 5 studs to the right each time it cloned?

Hey, I'm new to scripting and I would like to know how you would move a part 5 studs to the right each time it is cloned using a for loop. (basically so it moves 5 studs to the right of the last cloned part's position)

I'm guessing you need to use a return statement to do this?

Here is my current code:

(it clones an object 70 times but in the same position)

local part = game.Workspace.PartToBeCloned


for i = 1, 70 do
local clone = part:Clone()
clone.Parent = game.Workspace
clone.Anchored = true
clone.Position = Vector3.new(0,0,0)
	end

1 answer

✓ Accepted answer

What you would do is update the variable part every time the part is cloned, and calculate the distance from that.

local part = game.Workspace.PartToBeCloned

for i = 1, 70 do
	local clone = part:Clone()
	clone.Parent = game.Workspace
	clone.Anchored = true
	clone.Position = part.Position + Vector3.new(5,0,0)
	
	part = clone
end

(You weren't adjusting it's position at all with your previous code too)

Hope this helps!

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