Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you prevent a player from falling apart when HumanoidStateType.Dead = false?

I disabled players from dying using the following script on the serverside. It mostly works the way it should. Once a players health hits 0, they are still alive...but unfortunately their character breaks apart. How would I go about making it so the players character stays intact?

A little testing on my own....I attempted to use the following code on the client side, and it APPEARED to work, however on the client that died you'd see it as if you were still intact and walking around, but from any other client that sees you it appears that you died and fell apart.

I'm working with R15.

player.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)

2 comments

0

how about you put that script in serverscriptservice or use remote event if only on client

1

Anchor the character, lol jk.

1 answer

✓ Accepted answer

Try doing this on the Server when a player is added to the game

ServerScript

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
	end)
end)

Since this is not replicated, you need to do the same thing on the client

Local Script

local player = game.Players.LocalPlayer

repeat wait() until player.Character ~= nil and workspace:FindFirstChild(player.Name) ~= nil

local humanoid = player.Character:WaitForChild("Humanoid")
humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)

The Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false) already prevents the JointBreak on its own once these are in place

EDIT: Since you seem to still be having issues, assuming you don't want to weld the player's parts on death, you can use the LoadCharacter() Event to instantly respawn when you die

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
		
		humanoid.HealthChanged:Connect(function(health)
			if health <= 0 then
				player:LoadCharacter()
			end
		end)
	end)
end)

I will note that there is a property of the Humanoid named "BreakJointsOnDeath" which is automatically set to true, however, it seems to be "Read-Only".

5 comments

0

This is essentially what I attempted to do, and it still showed the character died to all but the person who "died's" client. I used your information word from word in my coding, the player side local script was placed in the players StarterCharacterScripts.

0

Well that seems rather odd. When I test on a server in studio it works as intended (https://gyazo.com/36a020bb3cd9be9b7946305be4eed413)

0

Resetting does appear to work, however if the players Health hits 0 through damaging weapons, that is where I experience the discrepancies.

0

The damage is replicated fine as well. Prior to attempt to keep the player from dying, when fighting everything replicated as it should. If a player died, they died on all clients including their own.

This discussion is preserved as it was. New answers, comments, and votes are closed.