This was my first time attempting something like this sooo I know its bad and poorly done, sorry about that. SO basically I am trying to get the top 3 players to display on a gui that everyone sees at the end of the round, 3 players get displayed but they are not in order. On different clients they are in different orders and stuff. (they are supposed to be in order)
NOTE: This is in a Local Script
openUpGui.OnClientEvent:connect(function(winner)
local players = {}
for i,v in pairs(game.Players:GetChildren()) do
if v.Playing.Value == true then
playing = playing + 1
players[v.Name] = v.MatchKills.Value
end
table.sort(players)
end
changeHeader(string.upper(winner).." WIN")
changePersonalKillsText()
changeCoinsObtainedText(winner)
local i = 0
for name, kills in pairs(players) do
i = i + 1
if i < 4 then
if topSpots[i] then
topSpots[i].Visible = true
topSpots[i].nametext.Text = name
topSpots[i].ds.Text = name
if game.Players:FindFirstChild(name).Team == game.Teams.Survivors then
topSpots[i].nametext.TextColor3 = Color3.new(1,0,0)
elseif game.Players:FindFirstChild(name).Team == game.Teams.Infected then
topSpots[i].nametext.TextColor3 = Color3.new(0,1,.1)
end
topSpots[i].killstext.Text = tostring(kills)
topSpots[i].killsds.Text = tostring(kills)
end
end
end
-- set player data to text guis and stuff
open()
end)

7 comments
just a quick question, why do you set currentTop to -math.huge???
To make it so that the first number compared will be written. It would do no good if currentTop was initialized to 0, and all your numbers were negative. 0 is greater than all negative numbers, so nothing would ever be selected as the greatest value. Setting it to -math.huge basically just ensures that you get an answer, no matter what your numbers are.
oh ok thanks
I get an error on the line that says "tbl[currentTopPlr] = nil"
the error says "table index is nil"
I've updated my answer and added a check to make sure the top score exists. If not, it will make the player name "N/A" and the score 0.
thanks, it working good now!