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

Why does my animation still play even though I unequip a tool?

Asked by 5 years ago

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?

01local plr = game.Players.LocalPlayer
02 
03IdleAnim = script:WaitForChild("Idle")
04RunAnim = script:WaitForChild("Run")
05 
06script.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)
14end)
15 
View all 37 lines...

4 answers

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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.

01local plr = game.Players.LocalPlayer
02 
03local IdleAnim = script:WaitForChild("Idle")
04local RunAnim = script:WaitForChild("Run")
05 
06local run = plr.Character.Humanoid:LoadAnimation(RunAnim)
07local idle = plr.Character.Humanoid:LoadAnimation(IdleAnim)
08 
09local runE
10 
11script.Parent.Equipped:Connect(function()
12    runE=plr.Character.Humanoid.Running:Connect(function(value)
13        if value>0 then
14            playrun()
15        else
View all 40 lines...
0
Thank you very much! biggun428 8 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I can't tell you if it's the issue but i think that you need to use :Disconnect()

Log in to vote
0
Answered by 5 years ago
01local plr = game.Players.LocalPlayer
02local equiped = true
03IdleAnim = script:WaitForChild("Idle")
04RunAnim = script:WaitForChild("Run")
05local run = plr.Character.Humanoid:LoadAnimation(RunAnim)
06local idle = plr.Character.Humanoid:LoadAnimation(IdleAnim)
07 
08script.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()
View all 37 lines...
Log in to vote
0
Answered by 5 years ago

I think you need a Disconnect() in there

Answer this question