How can i make when the player dies, it respawns in another location?

I’m trying to make a backrooms game (as always i’m making a game lol) but when a char dies, it is supposed to go to the level run to the exit, but for some reason i can’t get them to teleport, and i don’t know why, i also have searched SEVERAL, i repeat, SEVERAL posts that has this problem, no one of those helped me.

If anyone helped me, i would appreciate.

6 Likes

You could try to make your own spawning logic by disabling CharacterAutoLoads from StarterPlayer. And each time you load the character, just reposition it. Make sure you have the list of positions ready through one means or another.

For the logic of knowing when the character is loaded, check for Player.CharacterAdded event.

5 Likes

Code example? i’m not a beggar i just want a example

4 Likes

you have to use Humanoid.Died so like

local part =   --- put the part here
game.Players.PlayerAdded:Connect(function(plr)
       local char = plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
wait(game:GetService("Players").RespawnTime + 0.25)
char:PivotTo(part.CFrame)
end)
end)

try this
3 Likes

nvm now i see why there’s this line

3 Likes

didn’t work, :(( i don’t know why, it doesn’t print anything

2 Likes

localscript? serverscript? where did u put it

3 Likes

both, a local script on starter character then i deleted because it was not working, then a serverscript service, a server script

1 Like

ima test it myself and if it doesnt work, then i will fix it then i’ll say the code

3 Likes

okay, thanks (i appreciate that lol)

2 Likes

Assuming your level is in the same universe as your base levels, you can use a property in the player instance called; “RespawnLocation”. It’s an object property which you can later on set to a spawnlocation in your death level and the player will spawn in that room. This also won’t use any confusing code!

Here is an example:

Players.PlayerAdded:Connect(function(PlayerInstance)
     PlayerInstance.CharacterAdded:Connect(function(CharacterInstance)
          PlayerInstance.RespawnLocation = workspace["Level_Run"].SpawnLocation
     end)
end)
6 Likes
local Players = game:GetService("Players")

local spawnArray = {} -- this is an array of spawns

Players.PlayerAdded:Connect(function(player)
	local function onCharacterAdded(character)
		local humanoid = character.Humanoid

		-- positioning method / spawn setter
		character:PivotTo(spawnArray[math.random(#spawnArray)].CFrame)

		humanoid.Died:Connect(function()
			task.wait(Players.RespawnTime + 0.25)
			player:LoadCharacter()
		end)
	end

	player.CharacterAdded:Connect(onCharacterAdded)

	player:LoadCharacter() -- assuming CharacterAutoLoads is disabled
end)

Implementation is kind of approximate.

1 Like

like this?

plr.RespawnLocation = workspace.RespawnLocation

it prints an error for me, idk why it says that it needs to be a spawnlocation

1 Like

Mhm that is correct. Just like that.

4 Likes

i appreciate your response, but that unfortunetaly don’t work, it just throws an error on my output saying that it needs to be a spawnlocation

3 Likes

works like a charm my bro, thank you, i just had to change a little line and done!!

3 Likes

Great. I am happy to assist you in your issue. Have a good day!~

4 Likes

Thanks!!! Great day too! Hope u get more solutions!

2 Likes

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