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)
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)
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)
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