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

I want to make a table and a table reading script?

Ok, so, I have this script that changes the rank tab according to their rank when they equip a uniform through a locker I have. The script works as it should but I have many rank tabs and I would like to make it a table, a table that will have both the rank tab ShirtGraphic ID and the rank needed to get the rank tab and a piece of code that will read the table and assign the specific rank tab. Here is a piece of code I made but that requires me to add each rank manually.

local group = 3264905

script.Parent.Changed:Connect(function()
	local character = script.Parent.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	if player:GetRankInGroup(group) == 1 then
		script.Parent.Graphic = "http://www.roblox.com/asset/?id=5035388574"
	end
end)

4 comments

0

you mean something like local Hi = { Rank = 1, Text = "Rank Epic 1" } but for all ranks?

0

well, i want the table to have both the ID for the rank tab and the rank ID and a piece of code that reads the rank ID from the table and then the shirt ID and adds it to the Graphic part

0

just something so i won't have to repeat the if statement for each rank

0

answered with something i think MIGHT work

1 answer

✓ Accepted answer

THIS MIGHT WORK:

local RankTable = { }
local Group = 3264905

local function CreateRank(Role_Number, ID)
  RankTable[#RankTable + 1] = { ['Rank'] = Role_Number, ['Rank_Graphic'] = ID }
end

local function FindRankGraphic(Role_Number)

 local Temp_Found = false

 for i = 1,#RankTable do
   if RankTable[i].Rank == Role_Number then 
     Temp_Found = true
     return RankTable[i].Rank_Graphic
   end
 end

 if Temp_Found == false then
   return "Unknown Rank Name"
 end

end

CreateRank(1, 5035388574)

script.Parent.Changed:Connect(function()
    local character = script.Parent.Parent
    local player = game.Players:GetPlayerFromCharacter(character)
    
    if FindRankGraphic(player:GetRankInGroup(Group)) ~= "Unknown Rank Name" then
      script.Parent.Graphic = "http://www.roblox.com/asset/?id=" .. FindRankGraphic(player:GetRankInGroup(Group))
    end
end)

to add a new rank name just do this function:

CreateRank(1, 5035388574) -- change first argument to role ID and second to the graphic

1 comment

0

that works, thanks

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