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

Tool walking anim won't stop playing?

Asked by 5 years ago

I've been working on a tool with custom walk and idle anims. The problem is, the running anim won't stop playing while the tool is equipped! The anims are supposed to only play while the tool is equipped, which went fine. The only problem is this walking animation one. It won't stop playing while you have the tool equipped. Below is the code for the weapon.

canAttack = true
local p = game.Players.LocalPlayer
local c = p.Character or p.CharacterAdded:Wait()
local Humanoid = c:WaitForChild('Humanoid')
repeat wait() until Humanoid ~= nil

local attack = Humanoid:LoadAnimation(script.Attack)
local walking = Humanoid:LoadAnimation(script.Walking)
local idle = Humanoid:LoadAnimation(script.Idle)
local moving = script.Parent.Moving

script.Parent.Equipped:Connect(function()
    script.Parent.Handle.Unsheath:Play()

    moving.Value = false
    equipped = true

end)

Humanoid.Running:connect(function(value)
    if value <= 0 then
        moving.Value = false
    elseif value > 0 then
        moving.Value = true
    end
end)

moving.Changed:Connect(function()
    if moving.Value == true and equipped == true then
        walking.Looped = true
        idle.Looped = false
        idle:Stop()
        walking:Play()
    end
    if moving == false and equipped == true then
        walking.Looped = false
        walking:Stop()
        idle.Looped = true
        idle:Play()
    end
end)

script.Parent.Activated:Connect(function()
    local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)

    if canAttack == true then
        script.Parent.Handle.Swing:Play()
        attack:Play()
        canAttack = false
        wait(.4)
        attack:Stop()
        canAttack = true
        script.Parent.CanDamage.Value = true
    end
end)

script.Parent.Unequipped:Connect(function()
    equipped = false    

    idle.Looped = false
    idle:Stop()
    walking.Looped = false
    walking:Stop()
end)

1 answer

Log in to vote
1
Answered by 5 years ago

Assuming moving is a BoolVal, at line 35 you checked if moving is true, not its value. You're supposed to do moving.Value == true (you did the same mistake multiple times in the script as well)

And also what's with the equipped at line 16, it's never been initialized before as a local var and will die when the function ends.

0
Crap. Thanks, man! Gonna try this out. I hate when I make this mistake of not saying .Value! Ultimate_Miner64 45 — 5y
Ad

Answer this question