So I had this error. If this question was already posted can you please tell me. Here is my code. I know I spelled something wrong. I updated my script based on the solution I was given but my animation isn't playing. Also want to thanks phxntxsmic, and JustinWe12 for trying to help me.
local ExcaliburAnimation = script["ExcaliburAnimation"] local player = game.Players.LocalPlayer if not player.Character then player.CharacterAdded:Wait() end local char = player.Character repeat char = player.Character wait() until player.Character ~= nil local humanoid = char.Humanoid local ExcaliburAnimationTrack = humanoid:LoadAnimation(ExcaliburAnimation) ExcaliburAnimationTrack:Play()
Your code is likely being called before the player's character is created. If the player's character has not yet been created, it will be equal to nil.
There are a few possible solutions to this issue. These are two solutions to the issue:
repeat wait() until player.Character
and
if not player.Character then player.CharacterAdded:Wait() end
Inserted into your code it would looks something like this:
local ExcaliburAnimation = script["Excalibur Animation"] local player = game.Players.LocalPlayer --if not player.Character then -- player.CharacterAdded:Wait() --end -- ^^ that would work when un-commented local char = player.Character repeat char = player.Character wait() until player.Character ~= nil local humanoid = char.Humanoid local ExcaliburAnimationTrack = humanoid:LoadAnimation(ExcaliburAnimation) ExcaliburAnimationTrack:Play()
Sometimes the character will load after the script has ran. It says humanoid index nil so I assume that character is nil. You should add a script that waits for the character to load in.
if not char then char = player.CharacterAdded:Wait() end
This should solve it if you insert it between 3 and 4