Hello, so I am making an ordered leaderboard system and I am converting my values to an array which I can use table.sort on. This works halfway and I have moved on to the next step which is the TextLabel. Problem is, the value im calling on the array is apparently “nil” even though it is defined clear as day.
Script Portion:
data2[#data2+1] = {points = points,data = data}
table.sort(data2, function(a,b)
return a.value > b.value
end)
local nameAndRank = Instance.new("TextLabel",first)
nameAndRank.Size = UDim2.new(0,150,0,50)
nameAndRank.BackgroundTransparency = 1
nameAndRank.TextSize = 30
nameAndRank.Font = Enum.Font.TitilliumWeb
nameAndRank.Text = data2.data .. " #" .. rank -- error line? rank is defined and data too
You can ask me for the full script. Help is always appreciated.
You are creating a table within a Table, you are trying to access it in another field where it doesnt exist according to the script:
local data2 = {}
data2[#data2+1] = {points = points,data = data} -- creates a table under the key
-- 0 + 1 = 1 meaning that the key name is "1"
data2.points -- Key isnt under the Original Table
data2[1].points -- Key is under the Key that was created which is a table
in order to access it you would need to do:
local stuff = data2[someindex] -- whatever number of items was in the Table before
nameAndRank.Text = stuff.data .. " #" .. rank -- error line? rank is defined and data too