Unable to cast string to int64

Hello. I’m adding an “Employee of the month” poster to my game. The way it works is that it iterates through the players and gets an IntValue that the player is a parent of and saves the player with the highest value of that IntValue. Then the script applies the player name into the ImageLabel and TextLabel. Issue is that for some reason it doesn’t apply the properties because of an error.

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)
end

Players.PlayerAdded:Connect(onPlayerAdded)

while true do
	task.wait(10)
	local employeeOfTheMonthData = ReturnEmployeeOfTheMonth()
	if not employeeOfTheMonthData then
		continue;
	end
	local id = employeeOfTheMonthData[1]
	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[1])
	print(employeeOfTheMonthData[2])
end
local employeeOfTheMonth = ReturnEmployeeOfTheMonth()
print (employeeOfTheMonth)

image

Any and all help is greatly appreciated.

Can you send a screenshot of the error and show where the error occurs?

This error is most likely coming from this line:

local plrAvatar, isReady = Players:GetUserThumbnailAsync(id, ThumbType, ThumbSize)

Verify that the id being passed is a number value and not a string. You can do this by adding a print statement to print id. I’m willing to bet this will end up being players’ username.

for i, player in ipairs(Players:GetPlayers()) do
		table.insert(playerTable, {
			player.Name, -- This is the value you are passing to GetUserThumbnailAsync() 
			player.BrickCount.BrickCountValue.Value
		})
	end

So sorry for the very very late response. How would I go about converting the player.Name into player.UserId? Should I just make another line containing the player.UserId?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.