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

How can I reverse this for loop to make it go from last to second without breaking the script?

I have tried switching the numbers a bit around, but i have realised that I'm stuck.

This is a ServerScript.

for i=2,game.Workspace.SnakeValues.BodyParts.Value do
	game.Workspace.Base.Snake[tostring(i)].CFrame = game.Workspace.Base.Snake[tostring(i-1)].CFrame
end

I need to make this go from the last to the second. As I mentioned previously, I can't seem to figure out how to make the numbers be correct, in order to have the intentional effect. Thank you for answering.

1 answer

✓ Accepted answer
for i=game.Workspace.SnakeValues.BodyParts.Value,2, -1 do
    game.Workspace.Base.Snake[tostring(i)].CFrame = game.Workspace.Base.Snake[tostring(i-1)].CFrame
end

making it start from the last to the second by reversing loop and adding a -1. Meaning it goes -1 step backwards every time.

1 comment

0

I tried this earlier but I had a value that broke it earlier, and I forgot about it, but it worked now! Thank you.

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