Issues with respawning twice (custom respawn and default Roblox respawn)

My question is linked to this one Calling :LoadCharacter( ) on a dead character causes them to respawn twice

Basically, I have a script that at the start of the game replaces the player’s character with a custom character. Upon pressing ‘q’, the character is killed and manually respawned again as the custom character.

local Players = game:GetService("Players")
local event = game.ReplicatedStorage.RemoteEvent
 
function loadCustomChar(player)
	local char = game.ReplicatedStorage.Pumpkin:Clone()

	char.Name = player.Name
	player.Character = char
	char.Parent = workspace
end

function onPlayerAdded(player)
	wait(5)
	loadCustomChar(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)

function killplayer(player)
	player.Character.Humanoid.Health = 0
	wait(2)
	loadCustomChar(player)
end
event.OnServerEvent:Connect(killplayer)

However, after ‘manually’ respawning the player, the default Roblox repawn system also respawns the character again. Even if I call player:LoadCharacter() before attempting to load the custom character, the issue persists.

I am wondering how the default respawn system works. If I call player:LoadCharacter() in the function killplayer without changing the character, then this issue does not occur, which leads me to believe there must be something about the character I am trying to set that is causing the issue.

function killplayer(player)
	player.Character.Humanoid.Health = 0
	wait(2)
	player:LoadCharacter()
end

This is the custom character:

Any help on this is greatly appreciated. I know I can disable CharacterAutoLoads, but I am not sure why this shouldn’t work.

Update: Interestingly, if I add a part to the custom character called Torso, this issue does not occur. Is this the expected behaviour?

1 Like

This seems hacky when StarterPlayer has support for custom characters so you don’t have to do this every time they respawn (unless you plan on using the default character). Additionally, you could check if their health is <= 0 before calling LoadCharacter to avoid it being called twice.

Maybe try to use flags to prevent overlopping, just a quick example:

local flag = false

if flag ~= true then
     flag = true
     -- Do your thing.
     flag = false
end

My issue with using StarterPlayer is that I only want certain players to have that custom character - when the game starts some players will receive that character etc.

I am not sure if this would solve the issue as I think it has to do with how Roblox detects whether you are alive or not from your character rather than it being called twice from a script unintentionally

Interestingly, if I add a part to the custom character called Torso, this issue does not occur. Is this the expected behaviour?