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.
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)
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.