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

Sword idle animation won't stop playing?

Asked by 5 years ago
Edited 5 years ago

So when a player dies with the tool equipped, and they respawn, then equip the tool then unequip it, the idle anim is still playing.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local tool = script.Parent
local swingsound = tool:WaitForChild("Swing")
local canattack = tool:WaitForChild("CanAttack")

local debounce = false
local delayForDebounce = .5

tool.Equipped:Connect(function()
    local Equip = script.Parent.Parent.Humanoid:LoadAnimation(script.Sword)
    Equip:Play()
    wait(1.5)
    local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
    idle:Play()
end)

tool.Activated:connect(function()
    if debounce == false then 
    local choose = math.random(1,3)
    canattack.Value = true
    if choose == 1 then
        debounce = true
        local swing1animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch1)
        swingsound:Play()
        swing1animation:Play()
        wait(delayForDebounce)
        debounce = false
    elseif choose == 2 then
        debounce = true
        local swing2animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch2)
        swingsound:Play()
        swing2animation:Play()
        wait(delayForDebounce)
        debounce = false
    elseif choose == 3 then
        debounce = true
        local swing3animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch3)
        swingsound:Play()
        swing3animation:Play()
        wait(delayForDebounce)
        debounce = false
        end
    end
end)

tool.Deactivated:Connect(function()
    canattack.Value = true
end)

tool.Unequipped:Connect(function()
    local hum = char:WaitForChild("Humanoid")
    for i, v in pairs(hum:GetPlayingAnimationTracks()) do
        v:Stop()
end
end)
0
did you try the variouble? ik i spelt it wrong 3wdo 198 — 5y
0
Wdym? Justingamer700 114 — 5y
0
oh i just looked at the title im dumb let me fix it 3wdo 198 — 5y
0
i thought you were saying it wont start playing 3wdo 198 — 5y
View all comments (2 more)
0
CRAP 3wdo 198 — 5y
0
I FORGOT TO PUT IT IN LUA 3wdo 198 — 5y

1 answer

Log in to vote
1
Answered by
3wdo 198
5 years ago
Edited 5 years ago
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local tool = script.Parent
local swingsound = tool:WaitForChild("Swing")
local canattack = tool:WaitForChild("CanAttack")

local debounce = false
local delayForDebounce = .5

tool.Equipped:Connect(function()
    local Equip = script.Parent.Parent.Humanoid:LoadAnimation(script.Sword)
    Equip:Play()
    wait(1.5)
    local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
    idle:Play()
end)

tool.Activated:connect(function()
    if debounce == false then 
    local choose = math.random(1,3)
    canattack.Value = true
    if choose == 1 then
        debounce = true
        local swing1animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch1)
        swingsound:Play()
        swing1animation:Play()
        wait(delayForDebounce)
        debounce = false
    elseif choose == 2 then
        debounce = true
        local swing2animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch2)
        swingsound:Play()
        swing2animation:Play()
        wait(delayForDebounce)
        debounce = false
    elseif choose == 3 then
        debounce = true
        local swing3animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch3)
        swingsound:Play()
        swing3animation:Play()
        wait(delayForDebounce)
        debounce = false
        end
    end
end)

tool.Deactivated:Connect(function()
    canattack.Value = true
end)

tool.Unequipped:Connect(function()
    script.Parent.idle:Stop() --im assuming its in the tool or what eve so ye
end
end)
Ad

Answer this question