When I load the game, the animations play and work properly.
But when I try to stop the animaitions it doesn't work.
local walkanim = script.Parent.Parent.Humanoid:LoadAnimation(script.Walk) local idleanim = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle) script.Parent.Equipped:Connect(function() local mouse = game.Players.LocalPlayer:GetMouse() local player = game.Players.LocalPlayer local mouse = game.Players.LocalPlayer:GetMouse() idleanim:Play() mouse.KeyDown:connect(function(key) if key == "w" then walkanim:Play() idleanim:Stop() end end) mouse.KeyUp:connect(function(key2) if key2 == "w" then walkanim:Stop() idleanim:Play() end end) end) script.Parent.Unequipped:Connect(function() walkanim:Stop() idleanim:Stop() end)
Any help would be nice. Thanks!
The codes inside the equipped function will continue to run so you have to Disconnect it. You can do it by writing the function as a variable like this
local pie = script.Parent.Equipped:Connect(function()
The function will still work like normal, this will just make it so that it can be used as a variables. After you've done this, you can disconnect it when you unequip the tool so like this.
script.Parent.Unequipped:Connect(function() walkanim:Stop() idleanim:Stop() pie:Disconnect()