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

Stop idle and run animations from playing after tool is unequipped?

If you scroll down and look for the unequipped function, that's the part that doesn't work. When I unequip my tool the idle and run animations should stop, but they still play.

Heres a short video of me unequipping it, idk how to use gyazo that well https://gyazo.com/104197d47e30d4cc1c155023619c7dd8

--Variables
humanoid = script.Parent.Parent.Humanoid

Running = script.Parent.Running
Idle = script.Parent.Idle
Attack = script.Parent.Attack

--Loads animations
runAnim = humanoid:LoadAnimation(Running)
idleAnim = humanoid:LoadAnimation(Idle)
attackAnim = humanoid:LoadAnimation(Attack)

--Animation locations
lookForIdle = script.Parent.Idle
lookForRun = script.Parent.Running
lookForAttack = script.Parent.Attack

script.Parent.Equipped:Connect(function() -- basically works fine
	humanoid.Running:Connect(function(speed)
		if speed >1 then
			idleAnim:Stop()
			runAnim:Play()
		else
			idleAnim:Play()
			runAnim:Stop()
		end
	end)
end)


script.Parent.Unequipped:Connect(function() -- doesn't stop my tool animations when unequipped, Error, "Stop is not a valid member of Animation" 
	lookForIdle:Stop()
	lookForRun:Stop()
end)


local debounce = false
script.Parent.Activated:Connect(function() -- Attack, pauses character and plays animation when activated
	if not debounce then
		debounce = true
		
		humanoid.WalkSpeed = 0
		attackAnim:Play()
		
		wait(2.5)
		humanoid.WalkSpeed = 16
		
		debounce = false
	end
end)

2 comments

0

I am sorry to disappoint you but I can figure it out, bud.

0

:/

1 answer

The problem is that when you're telling the animation to stop, you are tell the actual animation object and not the animation loaded in a humanoid. It should be fixed below.

also sorry I replied late.


--Variables
humanoid = script.Parent.Parent.Humanoid

Running = script.Parent.Running
Idle = script.Parent.Idle
Attack = script.Parent.Attack

--Loads animations
runAnim = humanoid:LoadAnimation(Running)
idleAnim = humanoid:LoadAnimation(Idle)
attackAnim = humanoid:LoadAnimation(Attack)

--Animation locations
lookForIdle = script.Parent.Idle
lookForRun = script.Parent.Running
lookForAttack = script.Parent.Attack

script.Parent.Equipped:Connect(function() -- basically works fine
    humanoid.Running:Connect(function(speed)
        if speed >1 then
            idleAnim:Stop()
            runAnim:Play()
        else
            idleAnim:Play()
            runAnim:Stop()
        end
    end)
end)


script.Parent.Unequipped:Connect(function() -- doesn't stop my tool animations when unequipped, Error, "Stop is not a valid member of Animation" 
    idleAnim:Stop()
    runAnim:Stop()
end)


local debounce = false
script.Parent.Activated:Connect(function() -- Attack, pauses character and plays animation when activated
    if not debounce then
        debounce = true

        humanoid.WalkSpeed = 0
        attackAnim:Play()

        wait(2.5)
        humanoid.WalkSpeed = 16

        debounce = false
    end
end)

1 comment

0

I already tried to do the idleAnim:Stop() and runAnim:Stop(), but it still doesn't disable the animations when I unequip my tool, idk why

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