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

why is my global leaderboard not working properly? [very stuck]

Asked by 5 years ago

so i was trying to make a global leaderboard and it went in the wrong directin it said this in the output but idk what it means

"Did you forget a colon? The first argument of member function GetNameFromUserIdAsync must be an Object"

ok the script is

for i = 1, 10 do
    local Sam = script.Sample:Clone()
    Sam.Name = i
    Sam.Parent = script.Parent.Frame.ScrollingFrame
    Sam.UserPos.Text = "[" .. tostring(i) .. "]"
    Sam.Score.Text = "Nil"
    Sam.Username.Text = ""
    Sam.LayoutOrder = i
    script.Parent.Frame.ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, 50 * i)
end

function UpdateGui()
    for i, v in pairs(game.Players:GetChildren()) do
        local Data = 1 -- This is your score.
        local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("Cash")
        DataStore:SetAsync(v.UserId, Data)
    end
    local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("Cash")
    local Pages = DataStore:GetSortedAsync(false, 10)
    local Data = Pages:GetCurrentPage()
    for k, v in pairs(Data) do
        if tonumber(v.key) >= 1 then
            local Frame = script.Parent.Frame.ScrollingFrame:FindFirstChild(tostring(k))
            if Frame then
                Frame.Username.Text = game.Players.GetNameFromUserIdAsync(v.key)
                Frame.Score.Text = tostring(v.Value)
            end
        end
    end
end

while true do
    UpdateGui()
    wait(2)
end

plz help me

if you want to help me further, ask me for the model so i can give it to u

1 answer

Log in to vote
0
Answered by
Vmena 87
5 years ago
Edited 5 years ago

You are using the following:

game.Players.GetNameFromUserIdAsync(v.key)

You should be using the following:

game.Players:GetNameFromUserIdAsync(v.key)

GetNameFromUserIdAsync() is a function and not a property, hence why you need a colon.

Syntax Matters

Ad

Answer this question