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

Animator is not a descendant of game?

When I do humanoid:LoadAnimation(animation), it brings the error that animator must be a descendant of game or is required to be. It also says humanoid instead sometimes. So I did the below:

while not Animator:IsDescendantOf(game) do
	wait()
end

But that creates an infinite loop after a player resets. Any solutions?

I tried a while loop until the humanoid is found in workspace but that doesn't work either.

1 answer

✓ Accepted answer

What your code snippet does is that it checks every (approx) 1/30th of a second for the Animator to be a descendant of DataModel (commonly referred to as game, due to that being the global keyword in scripts).

My solution would be to add an exception for when the character dies (note: I have not defined character. It's not possible for me to accurately get it for you based on the code provided. You will have to do that yourself):

while not Animator:IsDescendantOf(game) do --\\Start a while loop checking for the animator stuff.

	if character and character:FindFirstChild("Humanoid") then --\\If there is a humanoid & character.

		if (character.Humanoid.Health < 1) then --\\Check the health, if <1 then continue.

			break --\\Break out of the loop.

		end --\\End the statement.

	end --\\End the statement.

	wait() --\\Wait 1/30 seconds.

end --\\End the loop.

As a bonus, you could make it check every 0.5 seconds, and drastically improve performance. There's no need to check 30 times a second, that's just a waste. Learn to code cleanly & efficiently! Example code:

Instead of:

while true do --\\Start a while loop

	--\\Your code here

	wait() --\\Wait (approx) 1/30 seconds.

end --\\End the loop

You could try something like:

while true do --\\Start a while loop

	--\\Your code here

	wait(0.5) --\\Wait half a second

end --\\End the loop

In most cases the time difference wont matter, trust me. It is very uncommon to need a loop running that many times a second!

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