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

How do I stop the animation when the tool is unequipped?

Asked by 4 years ago
Edited 4 years ago
local Player = game:GetService("Players").LocalPlayer
---
local Tool = script.Parent
---
local Handle = Tool:WaitForChild("Handle")
--
local Character = Player.Character or Player.CharacterAdded:Wait()
--
local Mouse = game.Players.LocalPlayer:GetMouse()
--
local Humanoid = Character:WaitForChild("Humanoid")
--
local Anim = Humanoid:LoadAnimation(script.Parent:WaitForChild("GunDownAnim"))

------
function GunDown()
Anim:Play()
script.Parent.LocalScript.Disabled = true
script.Parent.GunScript.Disabled = true 
end

function GunUp()
    Anim:Stop()
script.Parent.LocalScript.Disabled = false
script.Parent.GunScript.Disabled = false
end
------

Tool.Unequipped:Connect(function()
    Anim:Stop()
    script.Parent.GunScript.Disabled = false
    script.Parent.LocalScript.Disabled = false
    local StopAnim1 = Humanoid:LoadAnimation(script.Parent.Fire)
    local StopAnim2 = Humanoid:LoadAnimation(script.Parent.Hold)
    local StopAnim3 = Humanoid:LoadAnimation(script.Parent.Reload)
    StopAnim1:Stop()
    StopAnim2:Stop()
    StopAnim3:Stop()
end)

Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "f" then
        GunDown()
    end

    if key == "g" then
        GunUp()
    end
end)

Hello, I am trying to script a gundown script, this is a local script in a tool and it disables the scripts that lets the player shoot, but the issue is that the Animation isn't stopping when the tool is unequipped.

1 answer

Log in to vote
0
Answered by
IrishFix 124
4 years ago

Im not entirely sure but in the parameters of the anim:Stop() you could put a fade time to make sure it does it, like:

Anim:Stop(0.5)

Hope i helped - Irish

Ad

Answer this question