I want to figure out a way to cancel a function spawned via “task.spawn”, I’m not really sure how to approach this as “task.cancel(function)” doesn’t appear to work.
ex:
local function LfLegMissingMoveAnims()
while task.wait() do
if Humanoid.MoveDirection ~= Vector3.new( 0, 0, 0) then
LfLegMissingIdle:Stop()
if LfLegMissingTrack.IsPlaying == false then
LfLegMissingTrack:Play()
end
end
if Humanoid.MoveDirection == Vector3.new( 0, 0, 0) then
LfLegMissingTrack:Stop()
if LfLegMissingIdle.IsPlaying == false then
LfLegMissingIdle:Play()
end
end
end
end
task.spawn(LfLegMissingMoveAnims)
--code here to cancel the ongoing task of "LfLegMissingMoveAnims"
I’ve heard that I should use coroutines but I’m not sure how to use/apply them in the same context as the previous code.