Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Sword idle animation won't stop playing?

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)

6 comments

0

did you try the variouble? ik i spelt it wrong

0

Wdym?

0

oh i just looked at the title im dumb let me fix it

0

i thought you were saying it wont start playing

0

CRAP

0

I FORGOT TO PUT IT IN LUA

1 answer

✓ Accepted answer
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)

This discussion is preserved as it was. New answers, comments, and votes are closed.