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

Multiple group Id array?

Asked by 4 years ago

How would I create a multiple group Id array that loops through to check in which group a player has the highest numerical value rank, and then display it as an overhead textlabel.

And how would I implement it into this code, without breaking it?

 Create'BillboardGui'{
  Name = 'Nametag';
  Parent = Custom;
  Size = UDim2.new(5, 0, 0.5, 0);
  StudsOffset = Vector3.new(0, 2, 0);
  Create'TextLabel'{
   Name = 'NameLabel';
   BackgroundTransparency = 1;
   Size = UDim2.new(1, 0, 1, 0);
   Position = UDim2.new(0, 0, -0.8, 0);
   Font = 'ArialBold';
   Text = Character.Name;
   TextColor3 = Color3.new(1, 1, 1);
   TextScaled = true;
   TextStrokeTransparency = 1;
  };
  Create'TextLabel'{
   Name = 'RankLabel';
   BackgroundTransparency = 1;
   Size = UDim2.new(1, 0, 0.92, 0);
   Position = UDim2.new(0, 0, 0.2, 0);
   TextTransparency = .1;
   Font = 'SourceSansItalic';
   FontSize = Enum.FontSize.Size14;
   Text = Player:GetRoleInGroup(5965710);
   TextColor3 = Color3.new(1, 1, 1);
   TextScaled = true;
   TextStrokeTransparency = 1;
  };
 }

 Custom.BrickColor = Character.Head.BrickColor
 Character.Head.Changed:connect(function()
  Character.Head.Transparency = 1
  Custom.BrickColor = Character.Head.BrickColor
 end)
 Character.Head.Mesh.Changed:connect(function()
  Custom:WaitForChild('Mesh').MeshId = Character.Head:WaitForChild('Mesh').MeshId
 end)
end

local rainbow = function(callback)
local frequency = 0.1
local i = 0 
while true do wait()
local red = math.sin(frequency*i + 0)*127+128 
local green = math.sin(frequency*i + 2*math.pi/3)*127+128 
local blue = math.sin(frequency*i + 4*math.pi/3)*127+128 
callback(Color3.new(red/255,green/255,blue/255)) i = i+1 
end end 
function HandlePlayer(Player)
 if Player.Character then
  HandleCharacter(Player, Player.Character)
 end
 Player.CharacterAdded:connect(function(Character) HandleCharacter(Player, Character) end)
 if Player.UserId == 0 or Player.UserId == 0 or Player.UserId == 0 or Player.UserId == 0 then
  Player.CharacterAdded:connect(function(char) local label = char:WaitForChild("TastiesOverhead") 
   coroutine.resume(coroutine.create(rainbow),function(color)label.Nametag.RankLabel.TextColor3 = Color3.new(color.r,color.g,color.b)end) 
  end)
 end
end
game.Players.PlayerAdded:connect(function(b)
 HandlePlayer(b)
end)
for i,v in pairs(game.Players:GetPlayers()) do
  HandlePlayer(v) 
end 

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Howdy!

I'd try a for _,i do function to loop through all the values in the array. After all the numeric rank values are presented, I'd use math.max() to see which value was the highest. In fact, you probably won't even need to use an array. Check out what I have below.

local Group1Rank = Player:GetRankInGroup()
local Group2Rank = Player:GetRankInGroup()
local Group3Rank = Player:GetRankInGroup()

local HighestRank = math.max(Group1Rank,Group2Rank,Group3Rank)
if HighestRank == Group1Rank then
    local Role = Player:GetRoleInGroup()
    RankLabel.Text = Role
    [..]
elseif HighestRank == Group2Rank then
    local Role = Player:GetRoleInGroup()
    RankLabel.Text = Role
    [..]
elseif HighestRank == Group3Rank then
    local Role = Player:GetRoleInGroup()
    RankLabel.Text = Role
    [..]
end

Edit: I've changed the function a little to fit your needs. The Role variable grabs the name of the actual role and has it set as the text of the RankLabel.

If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.

Be sure to check out the Roblox API Documentation as well for additional reference.

0
Well, I really like your solution. However how would I put it into practice with my script? I'm actually not that experienced with scripting so additional explanation would be lovely! Question though, wouldn't that cause issues with the math.max? To my understanding, we wouldn't know what the name of the actual rank is called. I_Hashi 9 — 4y
0
I've edited my answer to fit your request. Also, you're right that we wouldn't get the role name from the rankID. However, we can grab the role name from the if then function of the highest group. TaxesArentAwesome 514 — 4y
0
I'd place it immediately after you establish the RankLabel itself. I'd say around Line 31 or 32. TaxesArentAwesome 514 — 4y
0
Thank you so much! Hopefully I can get in contact with you on discord instead of having to something else here. Have a good day! I_Hashi 9 — 4y
Ad

Answer this question