How do i stop a function loop?

I have a loop that i want to fire when the character speed is more than 1 and stop that loop when it goes below 1

self.Humanoid.Running:Connect(function(speed)
	if speed > 1 then
		movement = spawn(function()
			while task.wait() do
				GetQuadrant()
			end
		end)
	else
		movement = nil
		resetLocomotion()
		playAnimation(idle)
	end
end)

How do i stop it?

  1. spawn was deprecated 3 years ago. Use task.spawn
  2. Use task.cancel, then set movement to nil
  3. Do not spawn a thread for GetQuadrant if movement already exists

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