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

How do I make an on join, rank wise, team changer?

What I'm trying to figure out is how to make these scripts to work.

I have a folder full of scripts as such

local team = "Students"

game.Players.PlayerAdded:connect(function (Player)
if Player:IsInGroup(#####) and Player:GetRankInGroup(1) then
Player.TeamColor = game:GetService("Teams")[team].TeamColor
if Player.Character then
Player.Character.Humanoid.Health = 0
end
end
end)

What doesn't happen is other ranks getting put in their said teams. What I see is happening, is that the scripts obviously overlap since the higher ranks can also be put into the lower ranks teams.

Question being asked is how do I un-overlap them/ make them work so each rank gets put in the said team.

1 answer

✓ 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 = {
	-- Example:
--  1 = "Noob",
--  2 = "Beginner",
--  255 = "Master!"
--  220 = "Chairman"
--  etc.
	LowestRank = LowestRoleTeam,
	SecondLowestRank = SecondLowestRoleTeam,
	ThirdLowestRank = ThirdLowestRoleTeam,
	-- and so on
}

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

0

When stating, "game:GetService("Teams"):FindFirstChild(plr:GetRoleInGroup(group))" I get an error for "plr", should I make a local variable for localplayer?

0

Edited the script, it was a problem with me defining "player" but using "plr"

0

Hope that completes your script, be sure to mark the answer as correct!

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