Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

attempt to index nil with 'Humanoid?

Asked by 3 years ago

Hello, I have an error in my code that happens all the time when I animate it always does something like: attempt to index nil with Humanoid or attempt to index nil with Character. I'm not sure what to do anymore I used a script from not too long ago and the old script worked but the new one worked it's so confusing. I would like to say it does start in ServerStorage so that may be why. but I don't know. Anyway, This Is A LocalScript Inside of a Tool Inside of ServerStorage but it moves to the player backpack. so I don't know here is my script error is at line 1

local Anim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.SlashAnim2)

script.Parent.Activated:Connect(function()
   Anim:Play()
end)

2 answers

Log in to vote
0
Answered by 3 years ago

You forgot to put AnimationId at the end

local Anim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.SlashAnim2.AnimationId)

script.Parent.Activated:Connect(function()
   Anim:Play()
end)
0
Thanks For Your Help Still Does Not Work. CallMe_Axis 63 — 3y
0
Did you read the error he provided? That's not the issue. Plus, the LoadAnimation function takes an instance, not the animation id. This will only result in another error. xInfinityBear 1777 — 3y
0
I Was Not Sure Im So Desperate For A anwser at this point CallMe_Axis 63 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

It's saying the character is ni, in other words the script is running when the character hasn't loaded yet. Either put the script in LocalCharacterScripts that way the script is guaranteed to run because the script runs when the character loads or keep it where it is and modify the script a little bit

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait() --if player.Character is nil then wait for the character to be added before running the rest of the script
local Anim = character.Humanoid:LoadAnimation(script.Parent.SlashAnim2)

script.Parent.Activated:Connect(function()
   Anim:Play()
end)

Answer this question