Log in to vote

Assigning players to a specified team?

Asked by 13 days ago


I just made a very basic clicker game, and added a localscript which can detect a players country when joining the game (exactly this : ), i put it in the Starterplayerscripts because its the only way it works. So the main thing is : i want to assign players automatically to a specified team by their country, like if a player joins from Canada then he will be assigned to the "Canada" team, i want to do this but with like 100+ teams(countries). I tried everything today, i just cant figure it out to work sadly. Can somebody please help me to do it? Much thanks!

1 answer

Log in to vote
Answered by 12 days ago
Edited 12 days ago

What you could do is check if the Team/Country already exists in the Team service, in the scenario where it doesn't, it'll create an entire new team and place the player inside of that team, but if the team does already exist, it'll place them in the team.

local players = game:GetService("Players")
local LS = game:GetService("LocalizationService")
local teams = game.Teams

local function createTeam(name)
    local newTeam ="Team")
    newTeam.Name = name
    newTeam.Parent = teams
    return newTeam

    local foundRegion = LS:GetCountryRegionForPlayerAsync(player)
    if teams:FindFirstChild(foundRegion) == nil then
        local createdTeam = createTeam(foundRegion)
        player.Team = createdTeam
        player.Team = teams:FindFirstChild(foundRegion)

I tested this and it worked. I'm not the best scripter, but hopefully this helps!


Answer this question