this is a global leaderboard script, it works if there's one of them but it doesn't when I have multiple. it gives me a error of "Unable to cast string to int64", and supposedly the error happens on line 38
local datastore = game:GetService("DataStoreService")
local players = game:GetService("Players")
local globalstore = datastore:GetOrderedDataStore("globalgold1")
local board = workspace.GoldBoard.Part
local temp = board.SurfaceGui.ScrollingFrame.Frame:Clone()
board.SurfaceGui.ScrollingFrame.Frame:Destroy()
local function update()
for _,child in pairs (board.SurfaceGui.ScrollingFrame:GetChildren()) do
if child:IsA("Frame") then
child:Destroy()
end
end
local suc, err = pcall(function()
local data = globalstore:GetSortedAsync(false,30)
local page = data:GetCurrentPage()
for rank,plrData in ipairs(page) do
local name = plrData.key
local money = plrData.value
if rank ==1 then
local npc = workspace:FindFirstChild("2")
if npc then
npc.UserId.Value = name
end
end
local new = temp:Clone()
new.PlrName.Text = players:GetNameFromUserIdAsync(name)
new.Stat.Text = money
new.LayoutOrder = rank
new.Parent = board.SurfaceGui.ScrollingFrame
end
end)
end
while true do
update()
wait(180)
spawn(function()
for _,plr in pairs (game.Players:GetPlayers()) do
globalstore:SetAsync(plr.UserId,plr.leaderstats.Gold.Value)
wait(180)
end
end)
end

3 comments
Does that give you the player in object form and not string? Try players:GetNameFromUserIdAsync(name).Name instead. I'm not sure if it'll work, but it's worth a shot.
Print out what name is and print out type(name) to see what datatype it is.
I'd try what @insane_r said. Print out type(players:GetNameFromUserIdAsync(name)). I'm assuming it's an IntValue as the error says Int64, but you can try it or do tostring(players:GetNameFromUserIdAsync(name))