My character is still playing the idle animation even though the tool is unequipped. This bug only occurs when the player spams to equip and unequip the tool. I have no clue what I’m doing wrong.
LocalScript inside of Tool which handles the animations:
Tool.Equipped:Connect(function()
ToolEquipAnimation:Play()
ToolEquipAnimation.Stopped:Connect(function()
ToolIdleAnimation:Play()
end)
end)
Tool.Unequipped:Connect(function()
for _, AnimationTrack in pairs(Animator:GetPlayingAnimationTracks()) do
if AnimationTrack.Name == "R15ToolIdle" then
AnimationTrack:Stop()
end
end
end)
Tool.Equipped:Connect(function()
ToolEquipAnimation:Play()
ToolEquipAnimation.Stopped:Connect(function()
ToolIdleAnimation:Play()
end)
end)
Tool.Unequipped:Connect(function()
ToolIdleAnimation:Stop() --it looks like you have a variable already so this is what you need to do
end)
It still plays when tool is unequipped. I used a for loop to check all the playing animation tracks so that I could stop all the animation tracks from playing when unequipped but for some reason it still plays.
Sry for late replye i was asleep, all you need to do for the animation is
local tool = script.Parent --Change this
loval ID
local animation = tool.Parent.Humanoid:LoadAnimation(ID)
game:GetService("RunService").Heartbeat:Connect(function() --might need to change heartbeat to renderstepped
if tool.Parent:IsA("Model") and game.Players:FindFirstChild(tool.Parent.Name) then
animation:Play()
else
animation:Stop()
end
end)
No? It checks every frame if the tool is equipped and if the player is alive, if you unequip too quickly, it’ll be corrected next frame, basically nothing noticable.
Please be aware that this method is not particularly efficient and there exists a more efficient and effective alternative, such as listening to parent changes only. The solution I gave was the one that was initially thought of at that time.