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

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

Asked by
TtuNkK 37
3 years ago

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

Log in to vote
1
Answered by
Rinpix 639 Moderation Voter
3 years ago
Edited 3 years ago

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
Thanks mate! Works fine now! TtuNkK 37 — 3y
Ad

Answer this question