Wont spawn in correct spawn location occasionally [Team]

Whenever a player switches teams, it fires an event to the server. Then the server checks and so forth as shown in the code below. But there seems to be a 10%-30% chance of the player not spawning at the correct spawn when they switch teams. It spawns them at the “Spectator” spawn, which is the only neutral and auto-assigned team.

if team == "British" then
	if #britishteam <= #frenchteam then
		CRegiment.Value = regiment
		player.Team = game:GetService("Teams").British
		CRegiment.Value = regiment
		wait(.5)
		player:LoadCharacter()
	end
elseif team == "France" then
	if #frenchteam <= #britishteam then
		CRegiment.Value = regiment
		player.Team = game:GetService("Teams").French
		CRegiment.Value = regiment
		wait(.5)
		player:LoadCharacter()
	end
end
1 Like

I’ve also added this line of code before the LoadCharacter() and it still doesn’t work…

repeat wait() until player.Team == game:GetService("Teams").WhateverTeamItIs
1 Like

If you load in the character again, is it the same chance of ending up at the spectator spawn?

1 Like

Are you using your own spawn location system?

Roblox provides you one, which you can change the player’s team and use player:LoadCharacter() to teleport the player to a spawnlocation where you must go to properties and select the team.

1 Like

Yes, I use the roblox spawns. Which is weird why it glitches out sometimes…

Also, what is CRegiment and regiment?

1 Like

Yeah, I did that. Works now. I feel like there could be a better solution. But thanks though.


					player:LoadCharacter()
					wait()
					player:LoadCharacter()

I think you could also make your own Spawn Location system, that might be easy to do. If you need, i can make it for you if you want. Maybe i can.

1 Like

I’m guessing it’s a weird issue with how long you’re waiting, if you made it 2 seconds rather than .5, it would probably work all the time (or so I think). Glad that worked at the very least.

1 Like