Calling :LoadCharacter( ) on a dead character causes them to respawn twice

Has been a bug for a long time, probably just needs a check to see if the player has already respawned since it died.

Only occurs when Players.CharacterAutoLoads = true for obvious reasons

Might be nice to move this entire behaviour to lua to allow users to modify it e.g. in ServerScriptService (Slightly modified from this ):

local respawnTime = 5

local Players = game:GetService("Players")
Players.PlayerAdded:connect( function(Player)
	Player.CharacterAdded:connect(function(Character)
		local Humanoid = Character:FindFirstChildOfClass("Humanoid")
		if Humanoid then
			Humanoid.Died:connect(function()
				-- For backwards compatability of CharacterAutoLoads ( Users can now just override this script if they don't want auto loading )
				if Players.CharacterAutoLoads == true then
					wait(respawnTime)
					--Check they are still alive and it's the same humanoid
					if Player.Character == Character and Humanoid.Health <= 0 then
						Player:LoadCharacter()
					end
				end
			end)
		end
	end)
	-- Make them spawn the first time
	if Players.CharacterAutoLoads == true then
		Player:LoadCharacter()
	end
end)
7 Likes

I’m not sure if I’d classify that as an issue, considering, as you said, CharacterAutoLoads is true. I feel like the expected behavior would be that the system will attempt to force a respawn after a death occurred no matter what happens.

But…I can see how it would be beneficial if it checked to see if the character was currently alive before attempting it.

I’d say the expected behaviour would be:

if dead, respawn after 5 seconds

not:

once died, respawn after 5 seconds

The first being what I’ve said and the latter being how it currently is

… This may not make sense, I’m crap at explaining stuff.

2 Likes

Yeah I think I get what you mean. It shouldn’t attempt to respawn the character if they’re alive. The logic would be:

  1. Listen for Humanoid.Died event
  2. Wait 5 (or however long) seconds
  3. Check the player.Character property to see if there is a character and if it’s alive
  4. If an alive character exists, stop. If no character or dead character, respawn.
2 Likes

Yeah, I just updated the OP with that.

Although, for the last point, it would need to make sure it’s the same character else you could end up respawning before the 5 seconds is up if you reset, LoadCharacter and then reset again

That’s the problem – you can’t respawn a dead character. If you do, they’ll respawn a second time. You might suggest to let them wait it out, but if for instance I have a round-based game, I may want to respawn all players in the lobby immediately when the round ends, or the map when the round starts, so waiting isn’t an option. I think it makes more sense when you see the behavior in action:

External Media

First I reset, then I call LoadCharacter about 2 seconds after that, and then after I respawn, I respawn again 3 seconds later because ROBLOX’s spawn code respawns your character 5 seconds after it dies, unconditionally.

Going back to the round-based game, I respawn all players in the lobby. After I do that, whoever had died just before the round ended would spawn a second time in the lobby. I don’t want to have a custom spawn system – I just want to trigger respawning manually, so I don’t think writing my own spawn system is appropriate. ROBLOX’s spawn system should listen for LoadCharacter and cancel the default spawning if it’s called. That way, if I respawn someone after they die, they don’t spawn twice.

1 Like

Seems like the character respawning automatically when it’s already been respawned manually is always undesired behavior. It seems reasonable to fix this, I’ll look into changing this behavior.

11 Likes

Any possibility of it coming to lua?

Already possible, using this property:

Property bool Players.CharacterAutoLoads

Normally it’s set to true, but you can set it to false. That’ll stop the “game” (C code) from loading the character when the player joins or when the character dies. Combine it with PlayerAdded, CharacterAdded and Humanoid.Died and you can create your own spawning system. has been done before, that property has been around for quite a while

EDIT: I’m still selectively blind at times (more like selectively not blind but eh)

3 Likes

Please read thread. Already discussed.

1 Like

I just released the fix for this bug, let me know if you see any issues.

11 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.