Workspace.Tool.Script:11: attempt to index nil with 'LoadAnimation'

Hello Developers, I keep getting the error " Workspace.Tool.Script:11: attempt to index nil with ‘LoadAnimation’ ". The problem is I am loading the animation onto the players humanoid but my humanoid = nil until the player picks up the tool. how would I get around this?

1 Like

Load the animation when the tool is equipped

something like:

local anim = nil

tool.Equipped:Connect()
if not anim then
anim = humanoid:LoadAnimtion()
end
end)

Thank you so much for your help!

1 Like

Or you can just use

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid
local Animator = Humanoid.Animator
local Anim = Animator:LoadAnimation()
local Tool = script.Parent
Tool.Equipped:Connect(function()
   Anim:Play()
end)

I usually use server scripts when I make tools so that is my go to lol

local Player = script.Parent:FindFirstAncestorWhichIsA("Player")
local Character = Player.Character
local Humanoid = Character.Humanoid
local Animator = Humanoid.Animator
local Anim = Animator:LoadAnimation()
local Tool = script.Parent
Tool.Equipped:Connect(function()
   Anim:Play()
end)

Here’s a server script version.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.