Spamming tools breaks animations

video:

equip code:

StopAllAnimations()

coroutine.wrap(function()
	if equipping then 
		StopAllAnimations()
		return 
	end
	
	equipping = true
	task.wait(0.1)
	
	PlayAnimation("Equip", plr.Character.Humanoid)
	current_animation_track.Stopped:wait()
	if not equipping then return end
	
	StopAllAnimations()
	PlayAnimation("Idle", plr.Character.Humanoid)
	equipping = false
	equipped = true
end)()

unequip code:

pcall(function() update:Disconnect() end)
StopAllAnimations()
	
equipped = false
equipping = false

animation code:

local current_animation_instance = nil
local current_animation_track = nil
local current_animation_keyframe_handler = nil
local play_debounce = false

function StopAllAnimations()
	current_animation_instance = nil

	if current_animation_track ~= nil then
		current_animation_track:Stop()
		current_animation_track:Destroy()
		current_animation_track = nil
	end
end

function PlayAnimation(animName, humanoid)
	local animation = script.Parent.Animations:FindFirstChild(animName, true)
	
	if animation ~= current_animation_instance and not play_debounce then
		play_debounce = true
		
		if current_animation_track ~= nil then
			current_animation_track:Stop()
			pcall(function() current_animation_track:Destroy() end)
		end
		
		current_animation_track = humanoid:LoadAnimation(animation)
		current_animation_track:Play()
		current_animation_instance = animation	
		
		play_debounce = false
	end
end

i’m not sure, the most i can really give you is to add a cooldown between equipping tools to prevent spamming unless its a critical mechanic of your game to be able to switch quickly like that

1 Like

this is what i do, im not sure there is another way other then to make your own tool system since im pretty sure this is a roblox bug

It’s deprecated, try this instead or look at this api reference.

for _, AnimationTrack in pairs(script.Parent:GetPlayingAnimationTracks()) do
	AnimationTrack:Stop()
end

fixed by playing the animations that were broken then stopping all animations on unequip