Humanoid:ChangeState() not working

Hello DevForum,

I am here with an issue that I can’t seem to figure out, and research on the topic has brought me to unanswered forums and no solutions. So This is my last resort. Sorry if this has already been answered.

I recently figured out how to make an unpolished version of a toggleable ragdoll script, but everything works except for the changing of the humanoid state type.

Below is my code that changes the state of the humanoid, and disables the motor6Ds:

Activated.Changed:Connect(function()
	if Activated.Value == true then
		
		Character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics) -- Here is what it's not doing

		Character.HumanoidRootPart.RootJoint.Enabled = false
		Character.Torso["Left Hip"].Enabled = false
		Character.Torso["Right Hip"].Enabled = false
		Character.Torso["Right Shoulder"].Enabled = false
		Character.Torso["Left Shoulder"].Enabled = false
		Character.Torso.Neck.Enabled = false
	
	elseif Activated.Value == false then
		
		Character.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)

		Character.HumanoidRootPart.RootJoint.Enabled = true
		Character.Torso["Left Hip"].Enabled = true
		Character.Torso["Right Hip"].Enabled = true
		Character.Torso["Right Shoulder"].Enabled = true
		Character.Torso["Left Shoulder"].Enabled = true
		Character.Torso.Neck.Enabled = true
	
	end
end)

When I first made it, it was client sided and it worked well, but I switched it over to server sided and the changing of the state type just stopped working.

I’ve tried using other state types and it still will not change the state. Is it just a bug or am I doing something wrong?

Thank you.

3 Likes

You might need to define the Character if you’re doing it in a server sided viewpoint, cause LocalScripts can easily find the Player & Character while you gotta define the character/player in many different ways, try this maybe in line 1?

Activated.Changed:Connect(function(Character()

I should’ve mentioned this isn’t my entire script, there is a bunch of code above it but it doesn’t matter because all of it works perfectly, I defined character as the players character above in a variable. This is a server script inside the starter character.

According to Roblox Developer Hub, Humanoid:ChangeState() works every time when called, but:

Due to the default behavior of Humanoid some states will automatically be changed when set to. For example:

  • Setting the state to Swimming when the Humanoid is not in water will lead to it being automatically set to GettingUp

  • As it is unused, setting the state to PlatformStanding will lead to it being automatically set to Running

(RobloxDevHub, ChangeState, Humanoid | Documentation - Roblox Creator Hub, 30/12/2020)

Try printing states throughout the code execution using Humanoid:GetState().
Because I don’t know how exactly your script works, you should do some testing. Most likely ragdoll’s state will be automatically set to Running (because moving is present), like in the example below, which was answered recently. To make the ragdoll fall, it was enough to just change the state to Physics at the end of the code, no matter it immediately changing back to previous one.

3 Likes

Well if it has no joints to act upon then of course setting it to any state wont do anything

I will definitely try this, but I did find a solution where, it works on the client side but not the server, so I had a local script that changes it as the value changes and it worked perfectly fine. Thank you for your help!

2 Likes

When altering the Humanoid of a player, this should be done from a LocalScript ran by that player. Certain states only work locally.

A RemoteEvent OnClientEvent can be used for this.

5 Likes