Setting a Player's Team Before Character Spawn?

I’m having a technical difficulty here. I’m attempting to force a player to join the “Spectators” team before their characters load up and spawns into the game. Reason being is because the spawns aren’t neutral and the players will usually spawn in the middle of the baseplate instead of the Spectator spawns.

 players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		spawnAsSpectator:FireClient(player);
		print("TEST");
	end)
	print("TEST2");
	player:LoadCharacter() -- Spawn player character after to guarantee they will spawn as a Spectator
end)

In the above example, “TEST2” will execute first before “TEST” ever does, so I know that player:LoadCharacter() is being executed before the player.CharacterAdded:Connect(function(Character) function.

Is there a way around this or do I have to implement it another way?

2 Likes

add

game.Players.CharacterAutoLoads = false

this disables autorespawn
keep in mind that you do need to have some kind of respawn function

1 Like

Not sure why you have a remote event but you don’t need to fire the client to update a players team.

players.PlayerAdded:Connect(function(player)
	player.Team = game:GetService("Teams").Spectators
	player:LoadCharacter() -- Spawn player character after to guarantee they will spawn as a Spectator
end)

Or you could simply make the spectator team auto assignable. Its a property of the team object.

Note there may be a typo cause I am on mobile.

1 Like

For some reason, “TEST2” still happens to execute before “TEST” does. Is there a way to tell the game to wait until the Remote Event is fired before calling player:LoadCharacter()?

1 Like

It’s just the way my game works. I’m making a game where the server tells the clients what teams to choose and where to spawn, etc.

I also tried making the spectator team auto-assignable, however, my character is still getting spawned out in the middle of the baseplate instead of the Spectator spawns. Only when I reset my character (in-game) will it spawn me onto a Spectator spawn.

1 Like

Function Spawn(plr)
plr.Team = game:GetService(“Teams”).Spectators - - also try using player brickcolor - -
Wait(0.1)
plr:LoadCharacter()
end

Players.PlayerAdded:Connect(function(Spawn)

if we break this down in steps

this script
game.Players.CharacterAutoLoads = false

 players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		spawnAsSpectator:FireClient(player);
		print("TEST");
	end)
	print("TEST2");
	player:LoadCharacter() -- Spawn player character after to guarantee they will spawn as a Spectator
end)

first, the player joins
then there is a function that activates when a character is added (function does not trigger)
then there is a print (TEST2)
last there is load character
this will trigger the Function
the function will print (Test)

“Is there a way to tell the game to wait until the Remote Event is fired before calling player:LoadCharacter()?”

here are 3 options you can use how u like

Thanks! This worked great for some reason. I think what did it was the wait() function.