So, I have this code that auto teams you once you join the game based on your rank in my group. For some reason it is not working, I am looking for assistance to fix it. I will provide a screenshot below of the code.
Image:
So, I have this code that auto teams you once you join the game based on your rank in my group. For some reason it is not working, I am looking for assistance to fix it. I will provide a screenshot below of the code.
Image:
Try something like this.
--// Variables //--
local GroupId = 00000
--// Functions //--
game.Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(GroupId) == 255 then
Player.Team = game.Teams["NAME OF TEAM HERE"]
end
end)
Hope it works
Are you trying to team specific ranks or ranges of ranks?
I’m pretty sure, yes. [30charcharchar]
No it wouldn’t. You have to add an elseif statement like you did with your previous code, the only change being the
Player.Team = game.Teams["YOUR TEAM NAME"]
statement other than the
player.TeamColor
statement you put earlier.
No, just use elseif.
--// Variables //--
local GroupId = 00000
--// Functions //--
game.Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(GroupId) == 255 then
Player.Team = game.Teams["NAME OF TEAM HERE"]
elseif Player:GetRankInGroup(GroupId) == 111 then
Player.Team = game.Teams["NAME OF TEAM HERE"]
end
end)
If your’re wanting to team specific ranks, please use a Dictionary
local players = game:GetService("Players")
local ranksColors = {
[254] = BrickColor.new("Black"),
[250] = BrickColor.new("New Yeller"),
--Add more if needed
}
local groupid = --Your group id
players.PlayerAdded:Connect(function(plr)
local rank = plr:GetRankInGroup(groupid)
local color = ranksColors[rank]
if color then
plr.Team.TeamColor = color
end
end)
@BostonWhaIer Yours would work as well, but you wouldn’t really need to have an else
if @OP sets the default team as AutoAssignable
local PlayerService = game:GetService("Players")
local groupID = 000000000
local groupTeamTable = {
--[rank required] = the team
[255] = game.Teams:WaitForChild("Administration");
}
-- each indice in the table is the team that the player will be added to.
PlayerService.PlayerAdded:Connect(function(player)
local playerRank = player:GetRankInGroup(groupID)
if groupTeamTable[playerRank] ~= nil then
player.Team = groupTeamTable[playerRank]
else
-- just set the player's team to some default team
player.Team = game.Teams["Default Team or something..."]
end
end)
Something like this would work.
Please use a dictionary, that amount of if statements is unholy. Use what either I or @BostonWhaIer suggested, it’s way more organized
The people suggesting a dictionary are right. Also, the problem in your original screenshot is that you are using <=
where you should use >=
But does the way I did it work?
Yes it will but please for the sake of you and others, organize it with a dictionary