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

This animation wont play on Equipped?

local tool = script.Parent
local humanoid = tool.Parent:FindFirstChild("Humanoid")
local anim = humanoid:LoadAnimation(tool.Animation)

function onEquipped()
	anim:Play()
end

function onUnequipped()
	anim:Stop()
end

tool.Equipped.connect(onEquipped)
tool.Unequipped.connect(onUnequipped)

Could someone help me out?

1 answer

✓ Accepted answer

When the script first runs, the parent of the tool will be Backpack. This means that there won't be a Humanoid in it. You really have two options to fix this:


Wait until the tool is equipped to do the actions of line 2 and 3. This will mean that now the tool's parent is your Character, so there will be a Humanoid in it.

function onEquipped()
	local hum = tool.Parent:WaitForChild("Humanoid")
	anim = hum:LoadAnimation(tool.Animation)
	anim:Play()
end

The second option is to use the LocalPlayer and get the Humanoid from there.

local tool = script.Parent
local plr = game.Players.LocalPlayer
	repeat wait() until plr.Character
local chr = plr.Character
local hum = chr:WaitForChild("Humanoid")
local anim = hum:LoadAnimation(tool.Animation)

1 comment

0

Thanks so much!

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