How do I make it so the team is decided before the player loads in?

I currently have a system that makes it so that a player is given a team, based on their rank. However, this doesn’t work for spawn points, as they the player initially spawns in before the script actually runs, and therefore, they don’t spawn at the team spawnpoints, and spawn instead directly in the middle. how can I modify my script to fix this?

local Teams = game:GetService("Teams")
local Players = game:GetService("Players")

local function playerAdded(player:Player)
	
	local playerRank = player:GetRankInGroup(33160241)
	

	if playerRank == 2 then
		player.Team = Teams:FindFirstChild("Military")

	end
	
	if playerRank == 1 or playerRank == 0 then
		player.Team = Teams:FindFirstChild("Immigrant")
	end
	
	if playerRank == 254 or playerRank == 255 then
		player.Team = Teams:FindFirstChild("Premier")
	end
	
end

Players.PlayerAdded:Connect(playerAdded)
1 Like

Make sure your the TEAM COLOR of your spawnpoints match up with the team color of the actual team you’re trying to assign. For example,

If the police are navy blue, the spawn points team color must be navy blue for that team to spawn there

Yeah, they work, but only once the player resets after the initial load-in

Add player:LoadCharacter() at the end of your function

do i remove the autoload thing from players

You can keep that option enabled, as :LoadCharacter() will reload the players character regardless if it exists or not

2 Likes

image
like this?

Add it two lines under where you have it now, that way it will work for everyone joining rather than just people put into the Premier team

line 22, or 23? sorry, Im half asleep

1 Like

That’s all good.
image

tysm, its fixed! :heart: :heart: very helpful!!!

1 Like

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