Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Hypgnosis 186
5 years ago

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?

0
yes EpicMetatableMoment 1444 — 5y
0
you could set position of the player at the checkpoint's position after they spawn Louix27626 83 — 5y
0
Try just setting their team when they are added, then use [player]:LoadCharacter() GamingZacharyC 152 — 5y
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 GamingZacharyC 152 — 5y

1 answer

Log in to vote
0
Answered by
Kymaraaa 116
5 years ago
Edited by User#24403 5 years ago

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)
Ad

Answer this question