Repeat wait() script not stopping

So basically, I was making a field of view changer that is smooth, and I made it using repeat wait(). Whenever I go test it, it goes over the targeted value and it won’t stop!

Script:

repeat wait()
		workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView + 2
until workspace.CurrentCamera.FieldOfView == 90

You should use TweenService to prevent this from ever happening. It will also be significantly smoother.

local TweenService = game:GetService("TweenService")
local Tween = TweenService:Create(workspace.CurrentCamera, Tweeninfo.new(timeHere), {FieldOfView = 90})
Tween:Play()

If you wanted to use your less smooth method, change == to >= 90 and then force set it to 90.

I’ve tested this script on my own and it doesn’t work for me too. I printed the values in the output, and noticed that sometimes floats (decimal numbers) will appear and it’s not an integer anymore. Your computer tries to return approximate values at a point because of floating point imprecision. The solution would be to use the >= operator instead of the assigned to operator ==

Thanks, but it didn’t work.

30 Characters

I’ll try this out, thanks.

30 Character

Thanks, it worked!

30 Character AGAIN

1 Like