Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Unable to cast string to int64?

Asked by
0msh 333 Moderation Voter
4 years ago

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
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. Happy_Liam 64 — 4y
0
Print out what name is and print out type(name) to see what datatype it is. rokedev 71 — 4y
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)) killerbrenden 1537 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

new.PlrName.Text = players:GetNameFromUserIdAsync(tonumber(name))
0
Argument 1 missing or nil 0msh 333 — 4y
Ad

Answer this question