Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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)
2
change 1 to -1, simple as that :D cmgtotalyawesome 1418 — 4y
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 cmgtotalyawesome 1418 — 4y
0
Beat me to it mybituploads 304 — 4y
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 cmgtotalyawesome 1418 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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)

0
Cool! Great answer too :D Xapelize 2658 — 4y
0
If you would potentially be counting back from the previous set, you would flip 60 and 50 Ziffixture 6913 — 4y
0
Thank you for the answer! I didn't remember what that last number was so I left it blank. KyofuOmo 25 — 4y
Ad

Answer this question