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