Struggling to manually respawn the character

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

To respawn the character when in the ragdoll state.

  1. What is the issue? Include screenshots / videos if possible!

I’m just trying to make a simple ragdoll system, and so I need to turn off a few settings in the humanoid, like requiresneck = false, andPlatformStand = true and disable motor6D in the joints and temporarily replace them with ball socket constraints.

The problem starts is when entering the ragdoll state I start floating:

I have found that **humanoid.EvaluateStateMachine ** needs to be set to false (which I don’t understand why this is the case) which stops the floating glitch but now I have another issue, if i wanted to reset the players character it does not work.

  1. What solutions have you tried so far? Did you look for solutions on the Creator Hub?

I am aware that EvaluateStateMachine monitors the state of the player including triggering the dead state. So I have tried to have a propertyChange on the humanoids health on the server:

local Players = game:GetService("Players")

local function onCharacterAdded(character)
	local humanoid = character:WaitForChild("Humanoid")
	if humanoid then
print("Checking health")
	humanoid:GetPropertyChangedSignal("Health"):Connect(function()
		if humanoid.Health <= 0 then
			print("Player has died")

			
			humanoid.EvaluateStateMachine = true
			humanoid.PlatformStand = false

			local player = Players:GetPlayerFromCharacter(character)
			if player then
				task.delay(2, function()
					print("Respawning player: ", player.Name)
					player:LoadCharacter()
				end)
			end
			end
			
		end)
	end
end
	


Players.PlayerAdded:Connect(function(plr)
	
	print("Player has joined the game")	
	plr.CharacterAdded:Connect(function()
		print("Player has respawned")

		local Humanoid = plr.Character:WaitForChild("Humanoid")

		if Humanoid then 
			onCharacterAdded(Humanoid.Parent)

		end
	end)
end)


So on creating the character I have a function to check if player health is zero or below I attempt to Reload the character BUT in the ragdoll state it just does not work at all on the server.

I just want a general idea of just how to manually respawn the player character or to resolve my first problem which in the ragdoll state it starts floating up.

EDIT: GetPropertyChangedSignal on the server does not work on the server consistently in the ragdoll state but still works normally.

I am really unsure what is causing this

These are the settings I change in the ragdoll state:

Even with EvaluateStateMachine still set true, and not changing some settings mentioned above it still remains inconsistent or just not checking the changedproperty of health on the server

I can upload any part of my ragdoll script if needed to be checked specifically.

1 Like

disconnect player from character.

local char = plr.Character
plr.Character=nil
char.Parent=workspace


1 Like

As a temporary solution, you could create a tag upon the player getting ragdolled, thus signaling the program to initiate the respawn.

local PlayersService = game:GetService("Players")

local function OnCharacterAdded(plr, char)
	local tconn = nil
	tconn = char.ChildAdded:Connect(function(obj)
		if obj.Name == "I_GOT_RAGDOLLED" and tconn.Connected == true then
			tconn:Disconnect()
			wait(2)
			plr:LoadCharacter()
		end
	end)
end

PlayersService.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		OnCharacterAdded(plr, char)
	end)
end)

EDIT

Because I began programming in 2012 and utilize older practices? It’s a pre-2014 practice, btw.

Because that was one way you could tag something back then.

Cool.

Why are you using 2015 ahh methodics in modern day roblox? :skull:
Also why do you mention tags while using Instance? :skull:

local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")

CollectionService:GetInstanceAddedSignal("Ragdoll"):Connect(function(ins:Instance):()
	if not ins:IsA("Model") then return end
	local plr = Players:GetPlayerFromCharacter(ins::Model)
	if plr==nil then return end
	plr:LoadCharacter()
end)


Would make more sense

I am not sure where exactly to add this, I am guessing if the humanoid’s health reaches 0 (?)

humanoid:GetPropertyChangedSignal("Health"):Connect(function()
			if humanoid.Health <= 0 then
				local char = character
				local plr  = Players:GetPlayerFromCharacter(character)
				plr.Character = nil
				char.Parent=workspace
				
				
			print("Player has died")

Keep EvaluateStateMachine = false when ragdolled. Roblox doesn’t respect platformstand enough.
The respawn is a separate bug.

Does health go to zero? Exactly 0, not 0.001.
Is CharacterAutoLoads enabled?

yes correct hovewer you need to LoadCharacter for player manually after that aswell as to clean up old character

Keep EvaluateStateMachine = false when ragdolled

Okay got it.

Does health go to zero? Exactly 0, not 0.001.
Is CharacterAutoLoads enabled?

I believe both are correct:

It didnt print health on server 0. (at the final reset)

Edit: Maybe HumanoidState Dead is disabled on server? So .Died isnt triggered.

It works okay, but when first restarting the player it instantly destroys the player then anytime after will respawn normally, any reason why that happens?

Could be becouse you load character instantly
try putting a little delay, heartneat:Wait() will be more than enough i guess

This is the set up

	 connection = humanoid:GetPropertyChangedSignal("Health"):Connect(function()
			if humanoid.Health <= 0 and debounce == false then
				debounce = true
				print("Health on the server:", humanoid.Health)
				print("Player has died, is on the client", RS:IsClient())
				
				local plr = Players:GetPlayerFromCharacter(character)
				local char = plr.Character
				char.Parent=workspace
				plr.Character=nil
				
			
				
			--humanoid.EvaluateStateMachine = true
			--humanoid.PlatformStand = false

			local player = Players:GetPlayerFromCharacter(character)
				if player then
					
				task.delay(2, function()
					print("Respawning player: ", player.Name)
						player:LoadCharacter()
						connection:Disconnect()
						debounce = false
						
				end)

On first reset it ignores the delay
Edit:
okay I just movedlocal player = Players:GetPlayerFromCharacter(character) and replaced the plr now all the time it respawns instantly

Change them to be:

plr.Character=nil
char.Parent=workspace	

How does it work?

It has a very specific methamethod that makes character disconnected from player but makes character to be parented to nil

Also:

Heartbeat:Wait()
plr:LoadCharacter()
connection:Disconnect()
debounce = false

Okay, firstly how do I destroy the dis-attached character?
I have tried this but does not work:

			local player = Players:GetPlayerFromCharacter(character)
				local char = player.Character
				player.Character=nil
				char.Parent=workspace
				char.Name = "dead" 
				
				
			
				
			--humanoid.EvaluateStateMachine = true
			--humanoid.PlatformStand = false

			
				if player then
					task.wait(2)
				task.delay(2, function()
						print("Respawning player: ", player.Name)
						RS.Heartbeat:Wait()
						player:LoadCharacter()
						connection:Disconnect()
						debounce = false
						
						
						if char.Name == "dead" then
							
							char:Destroy()
							char = nil
						end

I changed the name because it respawn the player twice.

Also the original issue is that on the server humanoid:GetPropertyChangedSignal("Health"):Connect(function() does not work (sometimes)

(btw sorry for asking alot)

why are you creating a closure?
Just put task.wait
Put character to Debris so it will get handled automatically and you dont have to worry about it
Also set its name before parenting to avoid replication issues
You dont need getting rid of referance becouse memory gets free anyway (in your example it probably wont becouse yet again why the hell you are creating a closure?)

why are you creating a closure?

Do you mean local char = player.Character I think because I’m getting the character then dis attaching it then have the reference to that character then delete (If not then im just getting confused a bit).

no
Closure is a function that captures scope

So this local function onCharacterAdded(character)

Im talking about that if you didn’t understood

I think I’m not getting anywhere with how I made the code maybe because I’m getting an error in the output for trying to change the name

> The current thread cannot set 'Character's name' (lacking capability WritePlayer)

I still have the occurring issue of the server not responding to change in the humanoids health when in the ragdoll state. Maybe I rewrite the entire system again later but right now I am just confusing myself really. Thanks for the help anyway.