Tool animation doesn't want to work

What I tried so far is by doing this method

----- Location -----

local Tool = script.Parent

local player = game:GetService("Players").LocalPlayer

local character = player.Character

local animation = script.Parent:FindFirstChild("Eat")

local swingAnimation = character.Humanoid:LoadAnimation(animation)

---- Interacted ----

Tool.Activated:Connect(function(Player)

--- Animation ---
	
	swingAnimation:Play()

end

But the output comes out saying “Players.EdisonD316_Jake.Backpack.Sushi.LocalScript:11: attempt to index nil with ‘Humanoid’”

I don’t understand, after typing game:GetService(“Players”).LocalPlayer.Character the humanoid doesn’t appear after.

Any help?

1 Like

You need to wait for the character and humanoid to load in. Try something like this.

----- Location -----

local Tool = script.Parent

local player = game:GetService("Players").LocalPlayer

local character = player.Character or player.CharacterAdded:Wait()

local animation = script.Parent:FindFirstChild("Eat")

local swingAnimation = character:WaitForChild("Humanoid"):LoadAnimation(animation)

---- Interacted ----

Tool.Activated:Connect(function(Player)

--- Animation ---
	
	swingAnimation:Play()

end
1 Like

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