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

How to set player teams on join based on group rank?

Asked by 3 years ago

I'm currently trying to set it up so that players get placed into teams based on a group rank (such as rank ID, most likely.) Because, for example, I want the first rank, "Recruit," to go into a team named "Recruit." But then, I want the next 3 ranks, Private, Private First Class, and Corporal, to go into a team named "Low-Rank." How would I do this?

0
This website isn't for asking for scripts (at least from what I've heard), but to help with your scripts. I'd usually ignore these types of questions, but your question really interested me. I wouldn't be helping you create this script, but I'll just give you a tip. Make a table with your rank names, and their data is the team that they will be assigned on. If you want me help, hmu Itz Luan#1725 TheBigBro122 427 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

put this as a "Script" so it can run on the server (which means it shows on everyones screen since client means it only shows on one persons screen)

script is in serverscriptservice, explanation and comments in code block below.

local Teams = game:GetService("Teams") --Get the teams service.
game.Players.PlayerAdded:Connect(function(Player) --Checking if the game added a player to the game
    local PlayerRank = Player:GetRankInGroup(123456) --Get the players rank. Replace 123456 with your group ID.
    if PlayerRank == 1 then --If your confused on the number, go to your group configuration and look at the roles and check the role ID. Usually 1 is a low rank. 255 is the group leader.
        Player.Team = Teams:WaitForChild("PutYourTeamNameHere") --Set the players team to whatever the team name is. Replace PutYourTeamNameHere with the team name.
    elseif PlayerRank == 255 then
        if PlayerRank == 1 then --Same thing, if your confused on the number, go to your group configuration and look at the roles and check the role ID. Usually 1 is a low rank. 255 is the group leader.
            Player.Team = Teams:WaitForChild("PutYourTeamNameHere") --Set the players team to whatever the team name is. Replace PutYourTeamNameHere with the team name. Also, WaitForChild means waiting for the team to show up in the game.
        elseif PlayerRank == 255 then
            Player.Team = Teams:WaitForChild("PutYourTeamNameHere")
        end
    end
end)
Ad

Answer this question