Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Unable to cast string to int64?

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

0

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.

0

Print out what name is and print out type(name) to see what datatype it is.

0

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

1 answer

I believe that the name variable is a string. Try doing this on line 38 instead.

new.PlrName.Text = players:GetNameFromUserIdAsync(tonumber(name))

1 comment

0

Argument 1 missing or nil

This discussion is preserved as it was. New answers, comments, and votes are closed.