Hello. I’m making an “employee of the month” system for my game and I’m having issues with it applying the player stored in the table as the player to show on the poster. Everything prints fine, if player2 > player1 then it prints out player2 and whatever value they have.
local Players = game:GetService("Players")
local ImageLabel = script.Parent
local PlayerName = script.Parent.Parent.PlayerName
local function ReturnEmployeeOfTheMonth()
local playerTable = {}
for i, player in ipairs(Players:GetPlayers()) do
table.insert(playerTable, {
player.Name,
player.BrickCount.BrickCountValue.Value
})
end
table.sort(playerTable, function(a, b)
return a[2] > b[2]
end)
return playerTable[1]
end
local function onPlayerAdded(player)
local intValue = player.BrickCount.BrickCountValue
intValue.Changed:Connect(function()
local employeeOfTheMonth = ReturnEmployeeOfTheMonth()
print(employeeOfTheMonth)
end)
local id = player.UserId
local ThumbType = Enum.ThumbnailType.HeadShot
local ThumbSize = Enum.ThumbnailSize.Size150x150
local plrAvatar, isReady = Players:GetUserThumbnailAsync(id, ThumbType, ThumbSize)
ImageLabel.Image = plrAvatar
PlayerName.Text = player.Name
end
Players.PlayerAdded:Connect(onPlayerAdded)
while true do
task.wait(10)
local employeeOfTheMonthData = ReturnEmployeeOfTheMonth()
if not employeeOfTheMonthData then
continue;
end
print(employeeOfTheMonthData[1])
print(employeeOfTheMonthData[2])
end
local employeeOfTheMonth = ReturnEmployeeOfTheMonth()
print (employeeOfTheMonth)
pictures of explorer just in case:
Any help is greatly appreciated.