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

Why does the Animation still plays after tool is unequipped?

Asked by 5 years ago

Why does the Draw animation track still play when I unequip the tool. I unequip the tool and click and the animation plays?


local player = game.Players.LocalPlayer repeat wait(1) until player.Character local tool = script.Parent local character = player.Character local humanoid = character:WaitForChild("Humanoid") local player = game.Players.LocalPlayer local mouse = player:GetMouse() local SA = tool:WaitForChild("Ammo") local StoredAmmo = SA.Value local Reloading = false ----IDLE---- local Idleanimation = Instance.new("Animation") Idleanimation.Name = "Idle" Idleanimation.Parent = script.Parent Idleanimation.AnimationId = "http://www.roblox.com/asset/?id=3426547455" local Idleanimtrack = humanoid:LoadAnimation(Idleanimation) ----IDLE---- ----DRAW---- local Drawanimation = Instance.new("Animation") Drawanimation.Name = "Draw" Drawanimation.Parent = script.Parent Drawanimation.AnimationId = "http://www.roblox.com/asset/?id=3426686643" local Drawanimtrack = humanoid:LoadAnimation(Drawanimation) ----DRAW---- ----RELOAD---- local Realodanimation = Instance.new("Animation") Realodanimation.Name = "Reload" Realodanimation.Parent = script.Parent Realodanimation.AnimationId = "http://www.roblox.com/asset/?id=3426684428" local Reloadanimtrack = humanoid:LoadAnimation(Realodanimation) ----RELOAD---- tool.Equipped:connect(function() Idleanimtrack:Play() mouse.Button1Down:Connect(function() Drawanimtrack:Play() Idleanimtrack:Stop() end) mouse.Button1Up:Connect(function() Drawanimtrack:Stop() Idleanimtrack:Play() end) mouse.KeyDown:Connect(function(key) if key:lower() == "r" and StoredAmmo>=1 or key:upper() == "R" and StoredAmmo>=1 then Reloading = true Drawanimtrack:Stop() Idleanimtrack:Stop() Reloadanimtrack:Play() wait(2) Reloading = false Drawanimtrack:Stop() Reloadanimtrack:Stop() Idleanimtrack:Play() end end) end) tool.Unequipped:connect(function() Reloading = false Drawanimtrack:Stop() Idleanimtrack:Stop() Reloadanimtrack:Stop() end)
0
You could try disconnecting the connection, or if you're waiting until the tool is equipped and the left mouse is pressed then you could also use tool.Activated and probably get away from calling for Disconnect ABK2017 406 — 5y

1 answer

Log in to vote
1
Answered by
mado 40
5 years ago

The events you have in the Equip don't magically disconnect, you need to manually disconnect them or add a debounce. ex:

local Equipped 

tool.Equipped:Connect(function()
    if not Equipped then
        Equipped = true
    end
end)

tool.Unequipped:Connect(function()
    if Equipped then
        Equipped = false
    end
end)

Mouse.MouseButton1Click:Connect(function()
    if Equipped then
        AnimationTrack:Play()
    end
end)

Ad

Answer this question