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

How to stop a tool's idle animation after unequipping?

The idle animation does not stop after the tool is unequipped.

This is what I have:

local Screen
local Tool = script.Parent

local EquipAnimation = script.Parent.Equip
local UnequipAnimation = script.Parent.Unequip
local IdleAnimation = script.Parent.Idle



Tool.Equipped:Connect(function()


	local Humanoid = Tool.Parent.Humanoid
	local Track = Humanoid:LoadAnimation(EquipAnimation)

	Track:Play()


	if not game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("ScreenGui") then
		wait(2)
		Screen = script.Parent.ScreenGui:Clone()
		Screen.Parent = game:GetService("Players").LocalPlayer.PlayerGui
	end

	local Trackidle = Humanoid:LoadAnimation(IdleAnimation)

	Trackidle:Play()
	
end)


Tool.Unequipped:Connect(function()
	Screen:Destroy()
	Trackidle:Stop()
end)

1 answer

You gotta initialize the IdleAnimation first, so you can play and pause it as you need:

local Screen
local Tool = script.Parent

local EquipAnimation = script.Parent.Equip
local UnequipAnimation = script.Parent.Unequip
local IdleAnimation = script.Parent.Idle

-- I put the AnimationTracks at the top, this method is called "initialize"

local Trackidle = Humanoid:LoadAnimation(IdleAnimation)
local Track = Humanoid:LoadAnimation(EquipAnimation)

Tool.Equipped:Connect(function()


    local Humanoid = Tool.Parent.Humanoid

    Track:Play()


    if not game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("ScreenGui") then
        wait(2)
        Screen = script.Parent.ScreenGui:Clone()
        Screen.Parent = game:GetService("Players").LocalPlayer.PlayerGui
    end

    Trackidle:Play()

end)


Tool.Unequipped:Connect(function()
    Screen:Destroy()
    Trackidle:Stop()
end)

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