Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

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)
0
Could you try to remove the local infront of the variable? RebornedSnoop 175 — 2y

3 answers

Log in to vote
1
Answered by
SuperPuiu 497 Moderation Voter
2 years ago

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)
0
Ok thanks! imnotaguest1121 362 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

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!

Log in to vote
0
Answered by 2 years ago
  1. Removing the local infront of the variable because of the scope.

  2. Reversing the animation would be an option too. https://developer.roblox.com/en-us/api-reference/function/AnimationTrack/AdjustSpeed

AnimationTrack:AdjustSpeed(negative number to play it backwards)
0
what do you mean by removing the local? imnotaguest1121 362 — 2y

Answer this question