Setting respawnlocation

I have a folder with 4 models. Each model contains a respawn point called “respawnss”. Each model is named after a brick colour. This script auto assigns the team and the relevant respawn point. If in my script I set the players respawn location to the one inside that specific model, but all the respawns are called the same name, will it know which one I am referring to when the player dies in the future?

for r,t in pairs(game.Teams) do
		if t:GetChildren() > 0 then
			player.TeamColor = t
			local col = player.TeamColor
			local re = script.Parent.Tycoons:FindFirstChild("col")
			player.RespawnLocation = re.respawnss
		end
	end

This is an instance/service, and you are not getting it’s children here.

for r,t in pairs(game.Teams:GetChildren()) do

Here, you are using :GetChildren() (I’m not sure if that works, because I’m pretty sure it will get the children of the teams object), use :GetPlayer() Instead

if #t:GetPlayers() > 0 then

here, you are trying to set the player’s TeamColor to the team itself, change it to t.TeamColor.

Here you are just trying to find a tycoon named “col” change it to the variable col instead of a string.

for r,t in pairs(game.Teams:GetChildren()) do
		if #t:GetPlayers() > 0 then
			player.TeamColor = t.TeamColor
			local col = player.TeamColor
			local re = script.Parent.Tycoons:FindFirstChild(col)
			player.RespawnLocation = re.respawnss
		end
	end
2 Likes

Don’t you need to use # to get the length of the players table?

You are comparing a table with a number. It should look like this:
if #t:GetPlayers() > 0 then

Ah, yea sorry about that, I’ll fix it ty.

RespawnLocation is an instance reference so yes the engine will know which spawn you want the player to be spawning at even if they’re named the same. It would be a different story if it was asking for the name of the SpawnLocation.

2 Likes