Is there a better way to break out of this repeat loop?

snippet of the code

local shorter = script.Parent
		
shorter.WinchTarget = 5
shorter.WinchEnabled = true
		
repeat
	wait()
	print("looping", shorter.Length - shorter.WinchTarget)
until shorter.Length - shorter.WinchTarget <= 0.3
		
print("eyr")
shorter.WinchTarget = 240

my issue with this is that theres a little pause before winchtarget is set to 240 and ideally i want to instantly go from 5 to 240

you can either put the repeat loop in a task.spawn() thread, or you could just move the 240 line before the repeat line

i want the rope to reach a length of 5 before winchtarget is set to 240

Use RunService.PreSimulation:Wait() instead of using wait()

the slight pause is still there

having an infinite loop with a wait inside is not a good approach. Roblox has events for almost anything and you should use them.
Also a while loop is more appropriate here because in your case if the length is already less than 0.3 on the first iteration it will still call wait() once.

local shorter = script.Parent
		
shorter.WinchTarget = 5
shorter.WinchEnabled = true

while shorter.Length - shorter.WinchTarget > 0.3 do
    shorter:GetPropertyChangedSignal("Length"):Wait()
end
		
print("eyr")
shorter.WinchTarget = 240

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.