Custom character loading script not respawning character when falling to the void

I have a zombie loader script that respawn player whenever the player switched team. Usually when the players reset, their character will be respawn as normally, but i just discovered a new error that causing the players stucking in the void. Basically, when the player’s character fall into the void, they will end up stucking, this bug happens even player is not on the “zombies” team, and i don’t know how to solve this

Here is my script

local zombieteam = game.Teams.Zombies
local players = game:GetService("Players")
local mutations = game.ServerStorage:FindFirstChild("Mutations"):GetChildren()

players.CharacterAutoLoads = false

local spawntime = 5

local function randomize()
	local randomIndex = math.random(1, #mutations)
	local mut = mutations[randomIndex]
	return mut:Clone() 
end

local function copyAccessories(player, newZombie)
	local character = player.Character or player:LoadCharacter()
	if character then
		for _, accessory in pairs(character:GetChildren()) do
			if accessory:IsA("Accessory") then
				local clonedAccessory = accessory:Clone()
				clonedAccessory.Parent = newZombie
			end
		end
	end
end

local function spawnZombieWithAccessories(player)
	local newZombie = randomize()
	newZombie.Name = player.Name

	for _, script in pairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do
		local clonedScript = script:Clone()
		clonedScript.Parent = newZombie
	end

	copyAccessories(player, newZombie)

	player.Character = newZombie

	newZombie.Parent = workspace
	newZombie.HumanoidRootPart.CFrame = workspace["z team spawn"].CFrame + Vector3.new(0,1,0)
end

local function spawning(player)
	if player.Team == zombieteam then
		spawnZombieWithAccessories(player)
	else
		player:LoadCharacter() 
		local normalanimate = script.Animate:Clone()
		normalanimate.Parent = player.Character
	end
end

local function adding(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		humanoid.Died:Connect(function()
			wait(spawntime)
			spawning(player)
		end)
	end)

	spawning(player)
end

players.PlayerAdded:Connect(adding)

for _, player in pairs(players:GetPlayers()) do
	player:GetPropertyChangedSignal("Team"):Connect(function()
		spawning(player) 
	end)
end

players.PlayerAdded:Connect(function(player)
	player:GetPropertyChangedSignal("Team"):Connect(function()
		spawning(player)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	if player.Team == zombieteam then
		local zombie = workspace:FindFirstChild(player.Name)
		if zombie then
			zombie:Destroy()  
		end
	end
end)

Since player cannot respawn whenever they fell, this bug will be critical to the game.

This is the rigs i used, its pretty much the same to the roblox’s default rig

image

2 Likes

This might be happening because the HumanoidRootPart stopped existing

So i have to check if the humanoid root part is existing or not?

Yes exactly, if the HumanoidRootPart stopped existing, reload the player (Player:LoadCharacter())

1 Like

make sure you have a motor6d connects the upper torso to the head called “Neck” and make sure that your characters head part called “Head”

could you give me an example, i seems to cannot fix it

is a r6 rig, and yes my character does have a head and other body parts

1 Like

what about the neck motor6d ? this motor is so important to your characters to respawn

it does have a motor6d called neck, but the error im facing here is when the player fall to the void, which it removes all of the player parts and such

1 Like

Well i have another solution, instead don’t let the void kill the players

but if the void doesnt destroy my character so what will it do if a player accidently fall into it?

Will do nothing, they will just fall, but you could detect if their distance away from the baseplate is far away and teleport them back.

do you have any suggestion on how to do that?

Inside a RunService loop, check for the player’s position away from the baseplate if it got too big, reload the player.

OR

(Another fix: detect if the player died and then reload the player)

So i end up using a detector that if the player fell into any areas that is too deep then it will kill the player, which i find out helpful on preventing hacker

1 Like

you should make a map range detector, (if the range is greater then 1000 then kill the player) and also make the deletion barrier lower(click on workspace edit the height in properties). Also, using a “detector part” can be easily bypassed by disabling .cantouch by a hacker.

And last but not least: try and barrier the map off, open voided maps dont look as good as the ones that are closed in.

1 Like

i dont use a detection part, the script will detect base on the humanoidrootpart y axis, if it greater that -3500 then set the player health to 0

1 Like

That’s what i suggested, nice.

1 Like

you mean that you check if the humanoid root part Y is Less then -3500? since it would kill you at y axis 0 if you use greater than. Anyways, you should maybe also make a barrier around the map? (houses or smth like i said earlier) since (again) open voided maps look ugly and i know this from experience.

Sure, thanks for the suggestion.