Ragdoll death causes an unnecessary delay before respawning

Hello Developers.

I’ve made a ragdoll death script which used to work perfectly until right now as it suddenly causes an unnecessarily long delay before respawning or might just soft-lock the user. The script is located under StarterCharacterScripts and it’s a Server-Script (Just for anyone who is wondering.)

EDIT: Enabling Humaoid.BreakJoinsOnDeath removes this delay for some reason, but I do wish to keep the ragdoll death since this is literally what the script is about.

local Humanoid = script.Parent:WaitForChild("Humanoid")
Humanoid.BreakJointsOnDeath = false
local DeathSoundFolder = script:WaitForChild("DeathSounds")

Humanoid.Died:Connect(function()
	local Sounds = DeathSoundFolder:GetChildren()
	local RandomDeathSound = Sounds[math.random(1,#Sounds)]
	local SelectedDeathSound = RandomDeathSound:Clone()
	SelectedDeathSound.Parent = Humanoid.Parent.Torso
	SelectedDeathSound:Play()
	for index, Joints in pairs(script.Parent:GetDescendants()) do
		if Joints:IsA("Motor6D") then
			local BallSocket = Instance.new("BallSocketConstraint",Joints.Parent)
			local A1 = Instance.new("Attachment",Joints.Part0)
			local A2 = Instance.new("Attachment",Joints.Part1)
			BallSocket.Attachment0 = A1
			BallSocket.Attachment1 = A2
			A1.CFrame = Joints.C0
			A2.CFrame = Joints.C1
			BallSocket.LimitsEnabled = true
			BallSocket.TwistLimitsEnabled = true
			Joints:Destroy()
		end
	end
end)
1 Like

I’m having this same issue, when my character dies while NOT moving, it just simply stands still and the Humanoid.Died function doesn’t even fire, which for some weird reason delays the respawn time like a lot.
I have tried everything I could but I can’t get this to work.

Well, I’ve actually found something interesting about the issue I am having, apparently it doesn’t actually remove the Motor6D during the delay. (Sorry if the text is a bit sloppy Ig)

I actually discovered that Humanoid.Died doesn’t run on the server side if Humanoid.BreakJointsOnDeath is disabled, however, a suggestion I’ve been thinking is;

We make a localscript that fires when the localplayer dies, sends an event to the server requesting to ragdoll. You can check the player’s health on the server to avoid exploiting.

-- localscript (inside StarterCharacterScripts)

Humanoid.Died:Once(function()
	RagdolEvent:FireServer()
end)
-- script

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		local hum = character:WaitForChild("Humanoid")
		
		hum.BreakJointsOnDeath = false
	end)
end)

RagdollEvent.OnServerEvent:Connect(function(plr)
	local character = plr.Character
	if not character then return end
	
	local hum = character.Humanoid
	if hum.Health <= 0 then
		-- code :)
	end
end)

I haven’t tested it yet though, let me know if it works. And thanks for reporting this. :slightly_smiling_face:

Alright then, thanks! Also, mind if you explain where I put the Server-Sided script at?

You could put it in ServerScriptService.

hi!

a simple fix to this would be to manually load the character when the ragdoll is initiated, like so:

task.spawn(function() -- making it run seperately
	task.wait(game:GetService("Players").RespawnTime)
	player:LoadCharacter()
end)

That is not the issue. Like I mentioned before, Humanoid.Died doesn’t fire on the server side when Humanoid.BreakJointsOnDeath is disabled. That would be fix, but we’re trying to make the player ragdoll once it dies.

I have come to a possible fix to this issue, and hopefully it works. Thanks for helping though.

Sorry, I have made a few mistakes on the script. If it didn’t work, try the new version. Sorry for the incovenience.

Alright. This is final.
I have tested the script I’ve made, and it didn’t work.

Why? I found the problem, what happens is when Humanoid.BreaksJointsOnDeath is disabled, for some reason Humanoid.Health isn’t replicated to the server side, thus explaining why it doesn’t respawn and Humanoid.Died not firing on the server side.

I’ve made lots of changes to my code to make it work but I’m gonna show it here so you can see what’s different.

First, I created a BindableEvent and a RemoteEvent, naming both of them “ManualReset”. I put the BindableEvent inside the localscript and I put the RemoteEvent inside a ReplicatedStorage’s folder.

This is the localscript:

local player = game:GetService("Players").LocalPlayer
local character = script.Parent or player.Character

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RagdolEvents = ReplicatedStorage:WaitForChild("RagdollEvents")

local ManualReset = RagdolEvents:WaitForChild("ManualReset")

script:WaitForChild("ManualReset").Event:Once(function()
	ManualReset:FireServer()
end)

local StarterGui = game:GetService("StarterGui")
StarterGui:SetCore("ResetButtonCallback", script:WaitForChild("ManualReset"))

The localscript is inside StarterCharacterScripts.
What I did there was bind an event to the reset button, which fires another event to the server side.

This is the server script:

local Players = game:GetService("Players")
local ReplcatedStorage = game:GetService("ReplicatedStorage")
local RagdollEvents = ReplcatedStorage:WaitForChild("RagdollEvents")

local function InitiateRagdoll(character)
	-- your ragdoll code
end)

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local Humanoid = character:WaitForChild("Humanoid")
		Humanoid.BreakJointsOnDeath = false
		
		local connection
		local function disconnect()
			connection:Disconnect()
		end
		
		connection = Humanoid.Changed:Connect(function()
			if Humanoid.Health <= 0 then
				InitiateRagdoll(character)
				disconnect()
			end
		end)
	end)
end)

RagdollEvents.ManualReset.OnServerEvent:Connect(function(player)
	local character = plr.Character
	if not character then return end

	local Humanoid = character.Humanoid
	character.Health.Enabled = false
	Humanoid.Health = 0
end)

The server script is inside ServerScriptService
What I did there was when the reset event is called, the server sets the player’s health to 0.
Now, you’d think that would a fix to Humanoid.Died but it sadly isn’t. For some reason roblox simply refuses to make it work so it makes our lifes harder.

But I found a way around it, I made that everytime the player’s humanoid changes properties, it fires a function that checks if the player’s health is 0 and if so, it ragdolls the player.
The disconnect() function is to simply disconnect the Humanoid.Changed function once it ragdolls the player for the sake of the server’s performance. You don’t want it to be there clogging the server’s memory, specially because it fires repeatedly.



And that’s it. Honestly, it took a few days for me to find the solution. And until roblox fixes the issue, I’m gonna stick with this method.

Now, back to @imnotaguest1121’s ragdoll script, you should add these lines of code:

character.Head.CanCollide = true
character.LowerTorso.CanCollide = true
character.HumanoidRootPart.CanCollide = false

It avoids the head to shake like crazy, it avoids your ragdoll to dance while dead (remove the second line if you find it funny), and it makes that your HumanoidRootPart doesn’t collide with the 3D space.

Phew, that was long. Hope I helped! :melting_face:

2 Likes

Thanks Kappa! I although had to change the code however, but overall still work. Thanks man.

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