Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Parent of character is nil, but it clearly is in workspace, how do I fix this?

When my character resets or dies, it will give me an error saying LoadAnimation requires the Humanoid object (TtuNkK.Humanoid) to be a descendant of the game object. I went into dev forums, but none of them have worked for me. I discovered that when I print the parent of the character, it says its nil. Which is strange.. Any solutions for this? The code is in a local script parented to a tool.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
IdleAnim = character:WaitForChild("Humanoid"):LoadAnimation(game.ReplicatedStorage.Animations.Combat.CombatldleAnim)

1 answer

✓ Accepted answer

I think I had an issue with this about a month or two ago. I think it's a bug.

I think, for some reason, the character variable is referencing the character that once was in the Workspace but is no longer.

I'm pretty sure it's a bug on Roblox's part.

This is what I did to get around the issue:

local player = game.Players.LocalPlayer
local character
repeat
	wait()
	character = player.Character
until character

I don't know why, but it fixes it.

1 comment

1

Thanks mate! Works fine now!

This discussion is preserved as it was. New answers, comments, and votes are closed.