Hello. Once again I’m having issues with a script. This script fetches the data of all players present (name, id and an IntValue) and puts it into a table, sorts it, prints the player with the highest of that value. Then it returns the table and saves it as a function. Then every 10 seconds it updates the ImageLabel and TextLabel with the player that gets printed as the employeeOfTheMonth table. Or at least that’s what it should be doing. Instead it sets the ImageLabel and ImageText to the newest player that joined the game, unsure as to why as everything in the .PlayerAdded function seems fine.
TLDR: ImageLabel and TextLabel are set for the newest player in server, not the player that’s saved in the table
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.UserId,
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)
end
Players.PlayerAdded:Connect(onPlayerAdded)
while true do
task.wait(10)
local employeeOfTheMonthData = ReturnEmployeeOfTheMonth()
if not employeeOfTheMonthData then
continue;
end
local id = employeeOfTheMonthData[2]
local ThumbType = Enum.ThumbnailType.HeadShot
local ThumbSize = Enum.ThumbnailSize.Size150x150
local plrAvatar, isReady = Players:GetUserThumbnailAsync(id, ThumbType, ThumbSize)
ImageLabel.Image = plrAvatar
PlayerName.Text = employeeOfTheMonthData[1]
print(employeeOfTheMonthData)
end
local employeeOfTheMonth = ReturnEmployeeOfTheMonth()
print(employeeOfTheMonth)

Any help and tips are very much appreciated.
