NPC HumanoidState not changing

I need to set a R6 NPC’s HumanoidState to Physics, but it isn’t working

character.PrimaryPart:SetNetworkOwner(nil)
print(character.PrimaryPart:GetNetworkOwner())
humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
print(humanoid:GetState())
print(humanoid:GetStateEnabled(Enum.HumanoidStateType.Running))

the output prints

  20:34:24.927  nil  -  Server - objectMaker:217
  20:34:24.927  Enum.HumanoidStateType.Running  -  Server - objectMaker:220
  20:34:24.927  false  - 

It seems the ChangeState is being overridden of some sorts but I’ve looked into it and it seems it gets set to Running and then immediately gets changed to Physics.

Here’s some code I tried:

-- Disables all other Humanoid States
	for _, state in pairs(Enum.HumanoidStateType:GetEnumItems()) do
		if state ~= Enum.HumanoidStateType.Physics and state ~= Enum.HumanoidStateType.None then
			humanoid:SetStateEnabled(state, false)
		end
	end

	character.PrimaryPart:SetNetworkOwner(nil)

	humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	print("State is now:", humanoid:GetState()) -- This is printing Running
	
	while task.wait(0.1) do -- Then after a short duration (probably like 0.05/0.1 seconds) it starts printing Physics and doesn't stop printing Physics meaning it works
		print("State is now:", humanoid:GetState())
	end

This will print Running and then the while loop which is for demonstrational purposes seems to be printing Physics now. So this should work I just added the loop so you can see for yourself but it works for me now I think setting all the HumanoidStates to false is what fixed it.

This reminds me that I should specify my characters are R6 in the post

Did you test with R6?

No, but I just tried it. It still worked for me. Here’s my full code. Also, Make sure you’re using a Server Script.

game.Players.PlayerAdded:Connect(function(player: Player)
	task.wait(2)
	local character = player.Character
	local humanoid = character.Humanoid
	
	-- Disables all other Humanoid States
	for _, state in pairs(Enum.HumanoidStateType:GetEnumItems()) do
		if state ~= Enum.HumanoidStateType.Physics and state ~= Enum.HumanoidStateType.None then
			humanoid:SetStateEnabled(state, false)
		end
	end

	character.PrimaryPart:SetNetworkOwner(nil)

	humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	print("State is now:", humanoid:GetState()) -- This is printing Running
	
	while task.wait(0.1) do -- Then after a short duration (probably like 0.05/0.1 seconds) it starts printing Physics and doesn't stop printing Physics meaning it works
		print("State is now:", humanoid:GetState())
	end
end)


Thanks; I’ll test it when I get back in Studio

1 Like

So your post made me realize that there is some server-side delay with HumanoidStateType updates. So my server-owned NPCs were indeed changing to a Physics state.

However, for players, it is not possible to update their HumanoidStateType from the server, even if their NetworkOwnership is nil.

On the server, calling :GetState() on the Humanoid will return the server-set HumanoidStateType, but on the player’s side it remains unchanged. You have to use a RemoteEvent and change it from the client.

1 Like