Unable to cast string to int64 problem

Hi. I’m trying to make a global leaderboard for my game. It errors when I try to get the UserId of a player returning “Unable to cast string to int64”. Code:

local Wins = game:GetService("DataStoreService"):GetOrderedDataStore("Wins")
local players = game:GetService("Players")

local pColor = Color3.fromRGB(0, 122, 255)
local sColor = Color3.fromRGB(0, 62, 175)

local function CleanBoardSetup()
	for key,sufgui in pairs(script.Parent:GetChildren()) do
		if sufgui:IsA("SurfaceGui") then
			for index, val in pairs(sufgui.ScrollingFrame:GetChildren()) do
				if val:IsA("Frame") then
					val:Destroy()
				end
			end
		end
	end
end

local index = 1

function UpdateLeaderboard(data)
	for pos, currentpage in pairs(data) do
		for _,surfaceGui in pairs(script.Parent:GetChildren()) do
			if surfaceGui.Name == "SurfaceGui" then
				local score = currentpage.value
				local frame = script.LBFrame:Clone()
				frame.Parent = surfaceGui.ScrollingFrame
				frame.value.Text = score
				frame.rank.Text = "#" .. pos
				if pos % 2 == 0 then
					frame.BackgroundColor3 = pColor
				else
					frame.BackgroundColor3 = sColor
				end
				if pos == 1 then
					frame.rank.TextColor3 = Color3.fromRGB(255,211,0)
				end
				wait()				
				frame.name.Text = tostring(game.Players:GetNameFromUserIdAsync(currentpage.key))	
			end
		end
	end
end

while true do
	local success, message = pcall(function()
		local pages = Wins:GetSortedAsync(false,100)
		-- get data for first board
		local data = pages:GetCurrentPage()
		CleanBoardSetup()
		UpdateLeaderboard(data)
	end)

	if not success then
		print(message)
	else 
		print("board updated successfully")
	end
	wait(60)
end
1 Like

Use tonumber() to convert a string to a number.

2 Likes