Ragdoll Goes Through Ground Due To NetworkOwnership Changing

I am trying to create a ragdoll script, it works great, although when a player gets close the ragdoll’s limbs go through the ground because network ownership changes which is changing the state of the humanoid. I have tried looking through the devforum, but others also have this problem and I don’t see a fix. How do I fix this?

code:

local function ragdoll(character)
	
	character.Humanoid.WalkSpeed = 0
	character.Humanoid.PlatformStand = true
	character.Humanoid.BreakJointsOnDeath = false
	character.Humanoid.AutoRotate = false
	character.Humanoid.RequiresNeck = false
	
	character.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
	character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics,true)
	
	for i, v in pairs(character:GetDescendants()) do
		if v:IsA("Motor6D") then
			
			local attach0 = Instance.new("Attachment")
			local attach1 = Instance.new("Attachment")
			
			attach0.CFrame = v.C0
			attach1.CFrame = v.C1
			attach0.Parent = v.Part0
			attach1.Parent = v.Part1
			
			local ballSocketConstraint = Instance.new("BallSocketConstraint")
			ballSocketConstraint.Attachment0 = attach0
			ballSocketConstraint.Attachment1 = attach1
			ballSocketConstraint.Parent = v.Parent
			ballSocketConstraint.TwistLimitsEnabled = true
			ballSocketConstraint.LimitsEnabled = true
			v:Destroy()
			
		end
	end
	
	character.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
	character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.PlatformStanding,false)
	
	character.Humanoid.StateChanged:Connect(function(old,new)
		print(new)
	end)
	
end

Video:

https://gyazo.com/6f96c4979740c9aa2fbace80809ce793

You could maybe try setting it so when the character dies, it’s primarypart network owner is either the server or the player who died, preferably the player or reduce some load on the server.

It does that because it automatically changes the network owner when a player gets close enough, to prevent that you just have to set a network owner yourself

Network Ownership

1 Like

So I should set the ownership of the humanoidrootpart to the server right?

You could try both the Server and the player themselves, but I would generally recommend the player to put less strain on the server

I would probably do the server though, as it may then be easily hack-able, wouldn’t it?

I don’t believe that can easily be hackable? I’m not sure what you mean, but distributing the load to players rather than putting all of it on the server could cause less strain and is recommended rather than setting the owner to the server

I don’t think it could be easily hacked either

Should I maybe try doing the ragdoll entirely on client maybe? With on the server the npc just in a regular standing position on the ground in a physics state?

Just set the ragdoll to be owned by the Client themselves when they die, you’d have to call a RemoteEvent to make it ragdoll for everyone else on the client, it’s more time than setting the networkOwner

How exactly would I know who to set it to? Since it is not a player ragdoll, but a npc ragdoll. In the case of an npc ragdoll should I just send an event to the client to ragdoll the npc on their client?

Basically, do this

  • If it’s a dummy/NPC ragdoll, set it to the server
  • If it’s a player ragdoll, set it to the player who ragdolled

it referring to Networth Owner

Hm, I tried setting it, although the limbs still go through the ground for npcs.

Wait when did you try setting it? And could you show the code you have for that dummy

local function ragdoll(character)
	
	character.Humanoid.WalkSpeed = 0
	character.Humanoid.PlatformStand = true
	character.Humanoid.BreakJointsOnDeath = false
	character.Humanoid.AutoRotate = false
	character.Humanoid.RequiresNeck = false
	
	character.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
	character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics,true)
	
	for i, v in pairs(character:GetDescendants()) do
		if v:IsA("Motor6D") then
			
			local attach0 = Instance.new("Attachment")
			local attach1 = Instance.new("Attachment")
			
			attach0.CFrame = v.C0
			attach1.CFrame = v.C1
			attach0.Parent = v.Part0
			attach1.Parent = v.Part1
			
			local ballSocketConstraint = Instance.new("BallSocketConstraint")
			ballSocketConstraint.Attachment0 = attach0
			ballSocketConstraint.Attachment1 = attach1
			ballSocketConstraint.Parent = v.Parent
			ballSocketConstraint.TwistLimitsEnabled = true
			ballSocketConstraint.LimitsEnabled = true
			v:Destroy()
			
		end
	end
	
	character.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
	character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.PlatformStanding,false)
	
	character.Humanoid.StateChanged:Connect(function(old,new)
		print(new)
	end)
	
	local playerTry = game.Players:GetPlayerFromCharacter(character)
	if playerTry ~= nil then
		if character:FindFirstChild("HumanoidRootPart") then
			character.HumanoidRootPart:SetNetworkOwner(playerTry)
		elseif playerTry == nil then
			character.HumanoidRootPart:SetNetworkOwner(nil)
		end
	end
	
end

ragdoll(workspace:WaitForChild("Dummy"))

I set it after the ragdolled, should I do it before?

I think it’s the way you did the condition, for now, just comment out

if playerTry ~= nil then
		if character:FindFirstChild("HumanoidRootPart") then
			character.HumanoidRootPart:SetNetworkOwner(playerTry)
		elseif playerTry == nil then
			character.HumanoidRootPart:SetNetworkOwner(nil)
		end
	end

And do this

character.PrimaryPart:SetNetworkOwner(nil)

Working well like this! So, how should we make sure the ownership is set for the player? And how should I make sure the server wont get stressed out?

Again, we can do a simple check to confirm if it’s a player or not

local playerTry = game.Players:GetPlayerFromCharacter(character)
if playerTry then --Player exists from the character
	character.PrimaryPart:SetNetworkOwner(playerTry) --Sets it to the playerTry
else --Character ragdolled is not a player
	character.PrimaryPart:SetNetworkOwner(nil) --Sets it to the server
end

Proper networkship owning is a good way to not stress out the server

1 Like

Also quick question, do you think I will have to set the humanoid properties for a player on the client?

I don’t think so, they can work from a server script too

How should I fix the limbs going through the ground for players?