Can't change humanoid state type

Hello, guys. I’m working on a knock/carry/execute system, so basically when player’s health get lowered to zero, he gets knocked and someone can pick them up or finish. I’m using Echo Reaper’s Ragdoll Module in the knocked state, and when player gets knocked, I swap their humanoid state type to phyiscs and enable the ragdoll. But apparently ragdoll gets enabled and state is not changing. The following script located inside player’s character.

local PartsToRestore = {}

Humanoid.HealthChanged:Connect(function()
	if Humanoid.Health <= 1 then
		StatusManager:Create(Character,"Knocked")
		Ragdoller:Set(Humanoid,true)
		Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	end
end)

CharacterEvents.Carry.OnServerEvent:Connect(function(PlayerWhoCasted)
	local EnemyCharacter = PlayerWhoCasted.Character

	if not IsCharacter(EnemyCharacter) then
		return
	end

	local EnemyRootPart = EnemyCharacter:FindFirstChild("HumanoidRootPart")
	local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")

	if PlayerWhoCasted == Player then
		if HumanoidRootPart:FindFirstChild("CarryWeld") then
			HumanoidRootPart:FindFirstChild("CarryWeld"):Destroy()
			return
		end
	end

	if StatusManager:Has(Character,"Knocked") and not StatusManager:Has(Character,"Carried") and not StatusManager:Has(EnemyCharacter,"Carried","Stunned","Knocked") then
		StatusManager:Create(Character,"Carried")
		StatusManager:Remove(Character,"Knocked")
		Humanoid:ChangeState(Enum.HumanoidStateType.None)
		Ragdoller:Set(Humanoid,false)

		for i,v in pairs(Character:GetDescendants()) do
			if v:IsA("BasePart") then
				PartsToRestore[v] = v.CollisionGroup
				v.CollisionGroup = "Carried"
			end
		end

		local PrimaryWeld = Instance.new("Weld",EnemyRootPart)
		PrimaryWeld.Name = "CarryWeld"
		PrimaryWeld.Part0 = EnemyRootPart
		PrimaryWeld.Part1 = HumanoidRootPart
		PrimaryWeld.C0 = CFrame.new(0,2,1.2)

		PrimaryWeld.Destroying:Connect(function()
			for i,v in pairs(PartsToRestore) do
				i.CollisionGroup = v
			end
			Ragdoller:Set(Humanoid,true)
			Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
			StatusManager:Create(Character,"Knocked")
			StatusManager:Remove(Character,"Carried")
		end)
	end
end)

The result, when player gets knocked:
image
GetState prints out Enum.HumanoidStateType.Running

1 Like

You need to detect the state on the client, not the server.

Detect? What do you mean? I runned get state on clinet, change state can be used on server

Yes, but you need to have network ownership to change the state. You also need to disable the running state if you’re using an R6 rig.

I’m using an R15 rig. The script is inside of a character, it’s a starter character script, isn’t it a network owner?

If you change the state on the server, it might replicate slower to the client than what you’d expect. Maybe that’s the problem then?

It’s not! Not replicating at all. we’ll I didn’t wait longer than a minute, also it does change the state but only like one of the ten times.

Yeah, I thought so for R6 (but I thought it replicated for R15).

You’d need to change the state on the client, unfortunately.

1 Like

Alright, got it, but why isn’t this written in the :ChangeState() documentation. Ill test it and come back in a minute

I’m not sure. It’s probably obvious that it wouldn’t work, so why would they include it?

It can’t be not obvious. What if character is a mob or an npc, how do we handle states then? You are probably wrong.

I have fixed it. Apparently unlike the official documentation says, Enum.HumanoidStateType.Physics, somehow automatically changes to Enum.HumanoidStateType.Running, so I manually had to turn it off by setting it to not enabled. :SetStateEnabled(Enum.HumanoidStateType.Running,false)
image

1 Like

In my ragdoll script, I have a renderstepped connection to do this for me, but I guess that works too. Glad to see it’s solved now.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.