I have a script when a tool is equipped two animations "idle" and "run" but when I unequip the tool the animation still plays, Any help?
01 | local plr = game.Players.LocalPlayer |
02 |
03 | IdleAnim = script:WaitForChild( "Idle" ) |
04 | RunAnim = script:WaitForChild( "Run" ) |
05 |
06 | script.Parent.Equipped:Connect( function () |
07 | plr.Character.Humanoid.Running:Connect( function (value) |
08 | if value> 0 then |
09 | playrun() |
10 | else |
11 | playidle() |
12 | end |
13 | end ) |
14 | end ) |
15 |
You want to create and use LoadAnimation outside of these events so both event functions has the animation.
Also you want to disconnect the running event so that you don't create it over and over again.
01 | local plr = game.Players.LocalPlayer |
02 |
03 | local IdleAnim = script:WaitForChild( "Idle" ) |
04 | local RunAnim = script:WaitForChild( "Run" ) |
05 |
06 | local run = plr.Character.Humanoid:LoadAnimation(RunAnim) |
07 | local idle = plr.Character.Humanoid:LoadAnimation(IdleAnim) |
08 |
09 | local runE |
10 |
11 | script.Parent.Equipped:Connect( function () |
12 | runE = plr.Character.Humanoid.Running:Connect( function (value) |
13 | if value> 0 then |
14 | playrun() |
15 | else |
I can't tell you if it's the issue but i think that you need to use :Disconnect()
01 | local plr = game.Players.LocalPlayer |
02 | local equiped = true |
03 | IdleAnim = script:WaitForChild( "Idle" ) |
04 | RunAnim = script:WaitForChild( "Run" ) |
05 | local run = plr.Character.Humanoid:LoadAnimation(RunAnim) |
06 | local idle = plr.Character.Humanoid:LoadAnimation(IdleAnim) |
07 |
08 | script.Parent.Equipped:Connect( function () |
09 | equiped = true |
10 | plr.Character.Humanoid.Running:Connect( function (value) |
11 | if equiped = = true then |
12 | if value> 0 then |
13 | playrun() |
14 | else |
15 | playidle() |