This is pretty much a game breaking bug

Look in your player character in the explorer while in test mode. Do you still have your humanoid?

I think it is more with the game than a certain script to be honest. I will give you an example anyway tho
(This is part of the script, not all of it) Also I want to mention that it works completely fine until I die

local hum = char:WaitForChild("Humanoid")
local value = game:GetService("ReplicatedStorage").Values.Running
local jeep = workspace.CabinRetreat.Jeep1
local jeep2 = workspace.CabinRetreat.Jeep
local anim = hum:LoadAnimation(anims)


UIS.InputBegan:Connect(function(input,isTyping)
	if isTyping then 
		return
	elseif input.KeyCode == Enum.KeyCode.LeftShift then
		if value.Value == true then
			hum.WalkSpeed = 30
			if not hum.Sit then
			anim:Play()
			
			end
		end
	end
end)
1 Like

Yes, the humanoid is there the entire time

Is the script parented to a service like ReplicatedFirst or StarterPlayerScripts? The script is trying to load the animation on the previous humanoid (now destroyed).


If it isn’t, then you could try to make a function to make the event forcefully get the humanoid:

local function getHumanoid()
   return char:FindFirstChildOfClass("Humanoid")
end

This would return nil if the humanoid doesn’t exist.

Try this script so that it check if the humanoid is here or its still alive:

local hum = char:WaitForChild("Humanoid")
local value = game:GetService("ReplicatedStorage").Values.Running
local jeep = workspace.CabinRetreat.Jeep1
local jeep2 = workspace.CabinRetreat.Jeep
local anim = hum:LoadAnimation(anims)


UIS.InputBegan:Connect(function(input,isTyping)
	if isTyping then 
		return
     end
	if input.KeyCode == Enum.KeyCode.LeftShift then
           if hum ~= nil or hum.Health > 0 then
		if value.Value == true then
			hum.WalkSpeed = 30
			if not hum.Sit then
			anim:Play()
			end
		end
	end
end)

Also I would suggest don’t use the hum ~= nil try using if char:FindFirstChildWhichIsA("Humanoid") then end

It returns nil as you said. What should I do from here?

You could try to print the children of char using:

print(char:GetChildren())

to see all of it’s children and if the humanoid exists. Or try to see if there’s any scripts that interact with the humanoid. Mainly just normal debugging from this point

It returns a table with nothing in it: {}

Weird, the char variable might be having it’s children being removed by something. You could try redefining the variable whenever your character dies

The only thing it can find is the humanoid after I put this in

repeat wait() until char ~= nil

ok I made a for i,v loop and printed v, and now it is showing everything that it should

1 Like

But I still have no clue what the problem is

This is indeed really strange. However, I unfortunately don’t have the answer or solution.

i added this

while char.Parent == nil do
	char.AncestryChanged:Wait()

this makes the error not pop up anymore, but it still doesnt fix it

Maybe its because its trying to find the char or humanoid through the client instead of the server

Hello! Did you try putting the script in StarterPlayer > StarterCharacterScripts? This will run the script every time the character is loaded. You’ll still get the error unless you use a pcall function but it will still run like it’s supposed to.

1 Like

trying this rn, ill let you know if it works

THANK YOU SO MUCH! This worked completely well and there are now no errors whatsoever! I appreciate it a lot, my game has kind of a deadline and I needed to fix this error ASAP

no problem man, if you want the script to run 24/7 without error. use this to call the Humanoid.

local hum = char:WaitForChild("Humanoid", 0.1) --The 0.1 adds a timer for WaitForChild, so it's not just a while true do loop.

Usually when I see code like this and have an error where the Humanoid or character is having issues, it’s because of how Destroy() works. Destroy() does not set an instance to nil–instead, it actually sets the parent to nil. This means that if you have a variable pointing to the instance you call Destroy() on, it will still have access to this instance. How this is related to Characters and Humanoids is through the fact that when players die, internally the game calls Destroy() on their Character. This means that if in some script of your own you had something like local Character = Player.Character then after the player dies Character still points to something.

When I see your first line of code, local hum = char:WaitForChild("Humanoid"), I immediately notice that there is nothing such that everytime a new character is created (every time the player is spawned) the hum variable is not set to the new character’s Humanoid. This means that after dying and attempting to load an animation on the old humanoid the game errors because the humanoid doesn’t actually exist. This leads to the misleading situation that you state:

If you attempt to print the old Humanoid, you will get a result, leading you to believe that the Humanoid exists–which it does. Except, it’s the wrong Humanoid.

One solution to this is to set char to the new character every time the Player.CharacterAdded event is fired and to then set hum to the new Humanoid of the new Character. However, the cleaner solution is what @Laqotaa suggested, which is to simply put the script in StarterCharacterScripts. This is because whenever the player’s character is spawned, a new copy of the script is also loaded into the new character, which guarantees that every local hum = char:WaitForChild("Humanoid") points to the correct Humanoid.