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

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by
Ankur_007 290 Moderation Voter
5 years ago
Edited 5 years ago

The problem with your script is that the line: lua 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

```lua 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

```lua 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

0
When stating, "game:GetService("Teams"):FindFirstChild(plr:GetRoleInGroup(group))" I get an error for "plr", should I make a local variable for localplayer? DatBroDo -6 — 5y
0
Edited the script, it was a problem with me defining "player" but using "plr" Ankur_007 290 — 5y
0
Hope that completes your script, be sure to mark the answer as correct! Ankur_007 290 — 5y
Ad

Answer this question