Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a team auto assigner using group ranks?

I am trying to make it so that if you are a specific rank in my group you will become that sames ranks team in my game. This is the script I've been using so far

local groupid = 7240924
function onPlayerAdded(Player)
	if Player:GetRankInGroup(groupid) == 1 then 
       Player.Team = game.Teams.L1
	
	elseif Player:GetRankInGroup(groupid) == 2 then
       Player.Team = game.Teams.L2
 	
	elseif Player:GetRankInGroup(groupid) == 3 then
       Player.Team = game.Teams.L3
    
	elseif Player:GetRankInGroup(groupid) == 4 then
       Player.Team = game.Teams.L4
	
	elseif Player:GetRankInGroup(groupid) == 5 then
       Player.Team = game.Teams.L5
	
	elseif Player:GetRankInGroup(groupid) == 6 then
       Player.Team = game.Teams.L6
	
	elseif Player:GetRankInGroup(groupid) == 7 then
       Player.Team = game.Teams.L7

	elseif Player:GetRankInGroup(groupid) == 8 then
       Player.Team = game.Teams.L8

	elseif Player:GetRankInGroup(groupid) == 9 then
       Player.Team = game.Teams.L9

	elseif Player:GetRankInGroup(groupid) == 10 then
       Player.Team = game.Teams.L10
    end

end

I am new to scripting so it may be that its just wrong or that I'm putting it in the wrong place. If you could tell me where I need to put the script (workspace, startcharacterscripts, etc.) that would be very helpful.

2 comments

0

this is in a game.Players.PlayersAdded event right?

0

No it isn't. Should I make an event?

1 answer

Try this script and see the comments

-- Server Script [[ in ServerScriptService ]]
local groupId = 7240924
game:GetService("Players").PlayerAdded:Connect(function(plr)
     local PlayerRank = plr:GetRankInGroup(groupId) -- get the players rank
     local team = game:GetService("Teams"):FindFirstChild("F" .. tostring(PlayerRank)) -- get the team inside of the teams service
     if team and team:IsA("Team") then -- if team is NOT nil and the team Instance is a team
          plr.Team = team -- set the players team
     else
          -- put code in here what happens if there is not a team for the rank.
     end
end)

If this helps, please mark this as a solution!

This discussion is preserved as it was. New answers, comments, and votes are closed.