How do i stop a loop with wait()

I have quite a simple problem but i dont know the solution.

I have a script where it rotates a part in a while loop and i want to stop the loop after 10 seconds


done = false
while true do

	script.Parent.SeatsHandle.Orientation -= Vector3.new(0,1,0)
	
	task.wait(0.00001)
	if done == true then
		break
	end
	
end

wait(10)
done = true

use task.spawn so it doesnt yield

done = false

task.spawn(function()
	while not done do
		script.Parent.SeatsHandle.Orientation -= Vector3.new(0,1,0)

		task.wait(0.00001)
	end
end)

wait(10)
done = true
1 Like


task.spawn(function() -- creates and fires a coroutine
while done == false do -- fires until done is true

script.Parent.SeatsHandle.Orientation -= Vector3.new(0,1,0)
	
	task.wait()
end
end)


1 Like

Appreciate It very much , it worked !!

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