Can't change player HumanoidState

There HAS been a topic on this before, but the solution there didn’t help. I’m having the same problem as OP in that topic, I have a ragdoll system, and I can’t set the player’s humanoid state to physics, I’ve tried the code from the solution but it didnt work. It does easily switch the humanoidstate to physics on dummies, but not on a player. Here’s the code:

function injury.ragdoll(bool)
	task.spawn(function()
		while true do
			print(hum:GetState())
			wait(0.1)
		end
	end)
	if bool == nil then bool = false end
	for index, joint in pairs(script.Parent:GetDescendants()) do
		if joint:IsA("Motor6D") then
			hum:ChangeState(Enum.HumanoidStateType.Physics)
			hum:SetStateEnabled(Enum.HumanoidStateType.Running, false)
			socket = Instance.new("BallSocketConstraint")
			a1 = Instance.new("Attachment")
			a2 = Instance.new("Attachment")
			a1.Name = "ragdollat"
			a2.Name = "ragdollat"
			a1.Parent = joint.Part0
			a2.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2
			a1.CFrame = joint.C0
			a2.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			cl = joint:Clone()
			cl.Parent = joints
			value = Instance.new("StringValue", cl)
			value.Name = "jParent"
			value.Value = joint.Parent.Name
			joint:Destroy()
			if bool then
			local bv = Instance.new("BodyVelocity")
			bv.Parent = script.Parent.Torso
			bv.Velocity = Vector3.new(7, 0, 10)
			game:GetService("Debris"):AddItem(bv, 0.05)
			end
		end
	end
end
--It always prints Enum.HumanoidState.Running and therefore the ragdoll doesn't work properly
1 Like

are u using a local script or a script?

1 Like

this is a module, but im executing it from a server script

For change the player humanoid state i recommend using a local script.

U can use a boolvalue detector on player and change the value everytime the player is ragdoll, firing the local script to change the humanoid state.

1 Like

Thanks, that worked. I do have another question though. How do I stop this camera bob shown in the video from happening while ragdolled?

1 Like

I use this local script, which attaches the camera to a part of the character using tween service:

local RunService = game:GetService('RunService')
local PlayerService = game:GetService('Players')
local TweenService = game:GetService('TweenService')

local plr = PlayerService.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait()
local hum = chr:FindFirstChildWhichIsA('Humanoid')

local function Move()
	
	local ObjectToPoint 	-- Select the part of character to lock the camera
	
	local hrp, head = chr:WaitForChild('HumanoidRootPart'), chr:WaitForChild('Head')
	local Goal = {CameraOffset = (hrp.CFrame+Vector3.new(0,1.5,0)):PointToObjectSpace(ObjectToPoint.CFrame.Position)}
	local Tween = TweenService:Create(hum,TweenInfo.new(0.5),Goal)
	Tween:Play()
	
end

RunService.RenderStepped:Connect(Move)
1 Like

Nah, this doesnt work for me, I tried setting it to rootpart, head, torso, the bobbing is still there.

1 Like

Ah, nevermind, I just had to change the camera subject. Thanks @AnySaturn

2 Likes

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