Answered by
6 years ago Edited 6 years ago
You would use data-stores to save which team they were on. You can find more information on data-stores here.
For your particular case, it would be relatively simple. Just connect to the PlayerRemoving event and save to their data-store, and have it load their team on PlayerAdded.
Example Code:
01 | local playerService = game:GetService( "Players" ) |
02 | local datastoreService = game:GetService( "DataStoreService" ) |
03 | local teams = game:GetService( "Teams" ) |
05 | local playersTeamDatastore = datastoreService:GetDatastore( "Teams" ) |
08 | playerService.PlayerAdded:Connect( function (player) |
09 | local playerTeam = playersTeamDatastore:GetAsync(player.UserId) |
10 | if playerTeam and teams:FindFirstChild( tostring (playerTeam)) then |
11 | player.Team = teams:FindFirstChild( tostring (playerTeam)) |
16 | playerService.PlayerRemoving:Connect( function (player) |
17 | local playerTeam = player.Team |
18 | playersTeamDatastore:SetAsync(player.UserId, playerTeam) |
edit: i wrote "and if" for some reason, fixed