Basically, I have this tool module where it runs certain functions when a input is given. However, when I unequip the tool, this tool module class cancels all functions and animations. This doesn’t allow the animation.Stopped connection to run on the function. Is there any way to just cancel the other parts of the thread and keep that connection running (and possibly find a way to disconnect it after the animation is done?)
Example: (Players are not supposed to keep the extra walkspeed as it should be removed when the tool is unequipped. Also yields/stops the coroutine from running again).
--Some psuedo code to show basically what goes on. Formatted a bit weird because I wrote this directly.
task.spawn(function()
local Animation = Animator:LoadAnimation(AnimationID)
Animation:Play()
Humanoid.WalkSpeed = 8
Animation:GetMarkerReachedSignal("Marker"):Connect(function() -- Doesn't run if even if animation is stopped before the thread is canceled
Humanoid.WalkSpeed = 16
end)
end)
--Module where it cancels on unequip.
function ToolModule:CancelAllThreads()
for _,AnimationTable in pairs(self.AnimationsRunning) do
for _,Animation in pairs(AnimationTable) do
Animation:Stop()
end
end
for _,HitboxAction in pairs(self.Hitboxes) do
for _,Hitbox in pairs(HitboxAction) do
Hitbox:Stop()
end
end
for ThreadName,Thread in pairs(self.CoroutinesRunning) do
task.cancel(Thread)
self.RemoteListen:Fire("CD",ThreadName)
end
end