----- 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.
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