Character not respawning when dying to the void

The entirety of the time I’ve been working on my game, characters won’t respawn when dying to the void.
To try and counteract this, I’m trying to force the character to reload if the player has no HRP - but it still isn’t working

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


local function OnPlayerAdded(Player)
	Player:LoadCharacter()
	Player.CharacterAdded:Connect(function(Character)
		repeat wait() 

		until Character.Humanoid
		Character.DescendantRemoving:Connect(function(descendant)
			if Character:FindFirstChild("HumanoidRootPart")==nil then
				print("Died to the void?")
				Player:LoadCharacter()

			end
		end)
		Character.Humanoid.Died:Connect(function()
			print(Player.Name.." died")
			Player:LoadCharacter()
			print(Player.Name.."'s character loaded")

			repeat wait()

			until Character.HumanoidRootPart

		
		end)
		
	end)
end

Players.PlayerAdded:Connect(OnPlayerAdded)

Animation3

3 Likes

This post belongs in the #help-and-feedback:scripting-support category.

Anyways, here is the example code provided by the Player | Roblox Creator Documentation documentation page:

local Players = game:GetService("Players")

local respawnDelay = 5
 
Players.CharacterAutoLoads = false
 
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		-- find the humanoid, and detect when it dies
		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			humanoid.Died:Connect(function()
				wait(respawnDelay)
				player:LoadCharacter()
			end)
		end
	end)
	player:LoadCharacter() -- load the character for the first time
end)

It will simulate respawning. However, I would check if Players | Roblox Creator Documentation is enabled during runtime on the server in studio. Alternatively I would check the Players | Roblox Creator Documentation property during runtime to see if it’s set to a really big number.

Came up with a script that only triggers when you die to the void:

local players = game:GetService("Players")

function characterAdded(character)
	local player = players:GetPlayerFromCharacter(character)
	if not player then return end
	while not character:FindFirstChild("Humanoid")
		and not character:FindFirstChild("HumanoidRootPart") do wait() end
	
	character.HumanoidRootPart.AncestryChanged:Connect(function(_, parent)
		if character.Humanoid.Health == 0 then return end
		if not parent then
			print("void")
			player:LoadCharacter()
		end
	end)
end

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(characterAdded)
	if player.Character then characterAdded(player.Character) end
end)
5 Likes

I’ve tried using some things like :FindFirstChild or :WaitForChild, but both of them does not work

So i recommend you do a loop that gets all the baseparts that are in your character, check if one of that baseparts are the same as Humanoid.RootPart and then if it does not exists, it kills the character

Something like this:

local function findRootPart()
	for i,v in pairs(character:GetChildren()) do 
		if v:IsA("BasePart") then 
			if v == character.Humanoid.RootPart then
				local rootPart = v 
				return rootPart
			end
		end 
	end
end

And then another line that checks if that function could get the rootpart or not:

while task.wait() do
	local rootPart = findRootPart()
	if rootPart then
	    wait()
	else
        character.Humanoid.Health = 0
	end
end

The part that respawns the character is alright, so you just add something like this in the script

1 Like

it also triggers when you leave, leaving a empty player model how get rid of