✓ Accepted answer
The problem with your script is that the line:
if Player:IsInGroup(#####) and Player:GetRankInGroup(1) then
doesn't actually check for a corresponding rank, it just checks if the player has a rank, which is redundant since Player:IsInGroup() automatically tells us the player has a rank, default rank or not.
There are two ways you can approach this, you can
- Name all teams to whatever their corresponding role is
- Write up a table that has each rank and it's corresponding team
I would recommend using the first option since then it's easier for players to recognize ranks and it saves you the work to write up the whole table.
If group roles don't correspond to team ranks
local group = 123456789
local teams = {
LowestRank = LowestRoleTeam,
SecondLowestRank = SecondLowestRoleTeam,
ThirdLowestRank = ThirdLowestRoleTeam,
}
game.Players.PlayerAdded:Connect(function(player)
if player:IsInGroup(group) then
player.Team = teams[player:GetRankInGroup(group)]
end
end)
If group roles correspond to team ranks
local group = 123456789
game.Players.PlayerAdded:Connect(function(player)
if player:IsInGroup(group) then
player.Team = game:GetService("Teams"):FindFirstChild(player:GetRoleInGroup(group))
end
end)
Note: No need to duplicate these scripts, an individual script will do the job
Useful articles and pages:
Please comment if I have made any mistakes or you have any questions
3 comments
When stating, "game:GetService("Teams"):FindFirstChild(plr:GetRoleInGroup(group))" I get an error for "plr", should I make a local variable for localplayer?
Edited the script, it was a problem with me defining "player" but using "plr"
Hope that completes your script, be sure to mark the answer as correct!