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?
local plr = game.Players.LocalPlayer IdleAnim = script:WaitForChild("Idle") RunAnim = script:WaitForChild("Run") script.Parent.Equipped:Connect(function() plr.Character.Humanoid.Running:Connect(function(value) if value>0 then playrun() else playidle() end end) end) script.Parent.Unequipped:Connect(function() local run = plr.Character.Humanoid:LoadAnimation(RunAnim) local idle = plr.Character.Humanoid:LoadAnimation(IdleAnim) run:Stop() idle:Stop() end) function playidle() local run = plr.Character.Humanoid:LoadAnimation(RunAnim) local idle = plr.Character.Humanoid:LoadAnimation(IdleAnim) run:Stop() idle:Play() end function playrun() local run = plr.Character.Humanoid:LoadAnimation(RunAnim) local idle = plr.Character.Humanoid:LoadAnimation(IdleAnim) idle:Stop() run:Play() end
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.
local plr = game.Players.LocalPlayer local IdleAnim = script:WaitForChild("Idle") local RunAnim = script:WaitForChild("Run") local run = plr.Character.Humanoid:LoadAnimation(RunAnim) local idle = plr.Character.Humanoid:LoadAnimation(IdleAnim) local runE script.Parent.Equipped:Connect(function() runE=plr.Character.Humanoid.Running:Connect(function(value) if value>0 then playrun() else playidle() end end) end) script.Parent.Unequipped:Connect(function() run:Stop() idle:Stop() if runE then runE:Disconnect() runE=nil end end) function playidle() run:Stop() idle:Play() end function playrun() idle:Stop() run:Play() end
I can't tell you if it's the issue but i think that you need to use :Disconnect()
local plr = game.Players.LocalPlayer local equiped = true IdleAnim = script:WaitForChild("Idle") RunAnim = script:WaitForChild("Run") local run = plr.Character.Humanoid:LoadAnimation(RunAnim) local idle = plr.Character.Humanoid:LoadAnimation(IdleAnim) script.Parent.Equipped:Connect(function() equiped = true plr.Character.Humanoid.Running:Connect(function(value) if equiped == true then if value>0 then playrun() else playidle() end end end) end) script.Parent.Unequipped:Connect(function() equiped = false run:Stop() idle:Stop() end) function playidle() run:Stop() idle:Play() end function playrun() idle:Stop() run:Play() end