• Register a free account to view all forum content. Click here to create your own account.

My tool's holding animation wont play i cant figure out why?

Joined
Nov 17, 2018
Messages
7
Roblox
NoobletDeveloper
So i made an animation for a tool but it does the animation after i have un equipped the tool

my script:

"script.Parent.Equipped:Connect(function()
local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
animation:Play()
end)"
 
Joined
Nov 10, 2018
Messages
112
Ratings
11
Roblox
MythicalShade
You can use the tool.Unequipped event to detect when the tool is no longer equipped, then stop the animation. This code plays the animation as long as the tool is equipped, then stops as soon as it is unequipped.

Code:
local player = game:GetService("Players").LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local tool = script.Parent

local animation = humanoid:LoadAnimation(tool.Animation)

tool.Equipped:Connect(function()
    animation:Play() -- Play Animation when tool is equipped
end)

tool.Unequipped:Connect(function() -- Unequipped event
    animation:Stop() -- Stop Animation when tool is no longer equipped
end)