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

How do I make for loops go backwards? (Pretty new to for loops :/)

I'm trying to make my camera's FOV go backwards using for loops, but it seems that I can't make it go backwards. I'm trying to make the FOV go from 60 to 50, but I don't know how you can do that. I'm pretty new to for loops, as I have learned about how to use them about 2 weeks ago. Here is my script:

script.Parent.Equipped:Connect(function(mouse)
	mouse.Button2Down:Connect(function()
		local cam = workspace.CurrentCamera
		for f = 60, 50, 1 do
			cam.FieldOfView = f
			wait()
		end
	end)
end)

4 comments

2

change 1 to -1, simple as that :D

2

To explain it, the first number will always be the starting number, the second number will always be the end goal, and the third number is always the increment it counts by

0

Beat me to it

0

@mybituploads lol yeah but you got an answer so he can still accept it, just make sure to add an explanation in case he only reads the answer

1 answer

✓ Accepted answer

Instead of 1, you would use -1!

script.Parent.Equipped:Connect(function(mouse)
    mouse.Button2Down:Connect(function()
        local cam = workspace.CurrentCamera
        for f = 60, 50, -1 do
            cam.FieldOfView = f
            wait()
        end
    end)
end)

3 comments

0

Cool! Great answer too :D

0

If you would potentially be counting back from the previous set, you would flip 60 and 50

0

Thank you for the answer! I didn't remember what that last number was so I left it blank.

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