Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can I set a player's team before they spawn?

I'm using PlayerAdded to set certain Players' teams when they join the game. Group members join one team, etc, etc. However, I am not spawning in the correct position when I first join the game, but I spawn correctly after resetting.

SpawnLocations and Teams are set up correctly. No spawns are neutral and no teams are auto assignable.

I believe it is because I am spawning before the script is able to set my team. So is there any way to fix that?

4 comments

0

yes

0

you could set position of the player at the checkpoint's position after they spawn

0

Try just setting their team when they are added, then use [player]:LoadCharacter()

0

You will also need [Player]:IsInGroup(id) or local [VariableName] = [Player]:GetRankInGroup(id) but option two needs a checker (if [VariableName] [==, >=, or <=]) then and then change their team

1 answer

It's most likely that the Players Character is spawning before the PlayerAdded code can actually run.

To get around this you could do the following code:

game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		--you'd put any code relevant to the character here
		--it's good practice to put the character relevant code before the player relevant code
	end
	Player:LoadCharacter() --they'll spawn again at the new location
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.