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

Why won't the "Nil" change to the appropriate Value?

Asked by 4 years ago
for i = 1,10 do
    local Sample = script.Sample:Clone()
    Sample.Name = i
    Sample.Parent = script.Parent.SurfaceGui.Frame.ScrollingFrame
    Sample.UserPos.Text = "[".. tostring(i) .."]"
    Sample.Score.Text = "Nil"
    Sample.UserName.Text = ""
    Sample.LayoutOrder = i
    script.Parent.SurfaceGui.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
        local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("ScoreX1")
        DataStore:SetAsync(v.UserId,Data)
    end
    local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("ScoreX1")
    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.SurfaceGui.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

Answer this question