Teams based on group rank

Hey guys! It’s me again. I was just wondering how to make a script that I have absolutely no idea how to write.

  1. I am trying to write a script that places you on an in-game team based on your rank in a group

  2. My issue is that the tutorials that I have found on YouTube, the DevForum and ScriptingHelpers do not work

  3. I have looked all over the Developer Hub and the internet in general and have come across absolutely nothing

Thank you for helping me! I am a very amateur scripter and all the support really goes a long way!
Thanks in advance,
d_cyph

6 Likes

Create teams with the names of the group ranks in the teams service. Then, iterate through the players service with an “in pairs” loop and assign them the team.

for _,player in pairs(game.Players:GetChildren()) do --Indexes each player individually
	local GroupRank = player:GetRankInGroup(Your group id here)
	player.Team = game.Teams:FindFirstChild(GroupRank) --Looks for the group rank's name in the teams service and assigns it to the player.
end
1 Like

Try this:

local Team1 = game:GetService("Teams"):WaitForChild("Team1")
local Team2 = game:GetService("Teams"):WaitForChild("Team2")
local Group = GROUP_ID
local Rank1 = 50
local Rank2 = 25

function onPlayerAdded(Player)
     local PlayerRank = Player:GetRankInGroup(Group)
     if PlayerRank >= Rank2 and not (PlayerRank >= Rank1) then
          Player.Team = Team1
    elseif PlayerRank >= Rank1 then
          Player.Team = Team2
    end
end

game:GetService("Players").PlayerAdded:Connect(onPlayerAdded)
14 Likes

I tried that script. Did not work for me. I do not know that I could’ve executed it wrong but I don’t know.

5 Likes

Thanks, but where would I put this script?

Preferably ServerScriptService as this is a ServerScript and that’s where they belong.

4 Likes