Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Player keeps playing the Idle Animation for a tool, even when unequipped. Why Is that?

So I am some-what bad at scripting, but I decided to use this script, the script will play the Idle animation however when unequipped the Idle animation will keep playing even though I use :Stop()

Script:

local Tool = script.Parent
local Animation = Tool.Idle

Tool.Equipped:Connect(function()
	local Character = Tool.Parent
	local Humanoid = Character.Humanoid
	
	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()
end)

Tool.Unequipped:Connect(function()
	AnimationTrack:Stop()
end)

2 comments

0

Could you try to remove the local infront of the variable?

3 answers

✓ Accepted answer

Well, Uneqquiped function couldn't access AnimationTrack variable because it is a local variable in another function, so I made it a global one, hope it works (:

local Tool = script.Parent
local Animation = Tool.Idle
local AnimationTrack

Tool.Equipped:Connect(function()
    local Character = Tool.Parent
    local Humanoid = Character.Humanoid

    AnimationTrack = Humanoid:LoadAnimation(Animation)
    AnimationTrack:Play()
end)

Tool.Unequipped:Connect(function()
    AnimationTrack:Stop()
end)

1 comment

0

Ok thanks!

This is a quick simple mistake. :Stop() actually doesn’t exist. Here’s an actual script that works!

Tool.Unequipped:Connect(function()
    AnimationTrack:Pause()
end)

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.