Player not respawning at respective spawn location

Why my players touch a checkpoint, i set their spawn location to the checkpoint. When they die, they’re supposed to respawn at the spawn location. this is how i’m doing it now:

player.RespawnLocation =SpawnLocation
player.CharacterAdded:Connect(function(character)
	if player.RespawnLocation then
		character.HumanoidRootPart.CFrame = player.RespawnLocation.CFrame + Vector3.new(0,10,0)
	end
end)

however, when my player spawns, they always spawn at the default spawn location instead of this respawn location. my suspicion is that the respawn function code runs before the roblox spawn location code, as when i add a wait(1), they will spawn at the default location first and then get teleported to the respawn location.

any solutions for this?

1 Like

Yes your suspicion and solution is correct Roblox will do the default spawn first so waiting is necessary. Even the Roblox article on character added suggests this.

However you only need a run service stepped wait which is faster than the normal wait so it around 0.02 seconds I believe assuming 60 fps so it shouldn’t be noticeable.

Otherwise you can do a completely manually spawn system using player: LoadCharacter and disabling the default spawn system. I do not know if there is a way to modify the default spawn system or if it’s just built into the engine.

2 Likes