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

Why does my animation not stop when a player unequipped a tool?

Asked by 6 years ago
Edited 6 years ago

When I load the game, the animations play and work properly.

But when I try to stop the animaitions it doesn't work.

01local walkanim = script.Parent.Parent.Humanoid:LoadAnimation(script.Walk)
02local idleanim = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
03 
04script.Parent.Equipped:Connect(function()
05 
06    local mouse = game.Players.LocalPlayer:GetMouse()
07    local player = game.Players.LocalPlayer
08    local mouse = game.Players.LocalPlayer:GetMouse()
09    idleanim:Play()
10 
11    mouse.KeyDown:connect(function(key)
12        if key ==  "w" then
13            walkanim:Play()
14            idleanim:Stop()
15        end
View all 27 lines...

Any help would be nice. Thanks!

1 answer

Log in to vote
1
Answered by
Sorukan 240 Moderation Voter
6 years ago

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

1local 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.

1script.Parent.Unequipped:Connect(function()
2    walkanim:Stop()
3    idleanim:Stop()
4    pie:Disconnect()
0
This works, but why does my idle animation not work when I re-equip the tool? kittonlover101 201 — 6y
Ad

Answer this question