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!