0
votes

a question about Roblox studio, or rather, about dataStore. If you save the values directly in the script by the pointsStore:SetAsync ("Mars", 19) when outputting data:GetCurrentPage() - this value is output, but if you do this via a function, the value is saved, but does not appear when the data:GetCurrentPage(). How can I save user data?

save the values directly in the script:

PlayerPoints:SetAsync("Mars", 19)

local success, err = pcall(function()
    local Data = PlayerPoints:GetSortedAsync(false, 5)
    local WinsPage = Data:GetCurrentPage()

    print(WinsPage)
end)

save the values directly in the function:

local function givePointsPlayer(player, points)
    local pointsOld = pointsStore:GetAsync(player.Name.."&"..tostring(player.UserId).."&"..tostring(os.date("*t").month))
    if (pointsOld == nil) then
        pointsOld = 0
    end
    print(pointsOld)
    local success, err = pcall(function()
        pointsStore:SetAsync(
            player.Name.."&"..tostring(player.UserId).."&"..tostring(os.date("*t").month),
            pointsOld + points              
        )
    end)
end

EventEditPointsPlayer.OnServerEvent:Connect( function(player, points)
    givePointsPlayer(player, points)
end)

answer: answer

how do I need to save user data so that it is output via :GetCurrentPage() ??

1

1 Answers

0
votes

If you want to get the data from the pages, you need to write some code to go through each entry and page. Here's an example from the DevHub tutorial:

-- Sort data into pages of three entries (descending order)
local pages = characterAgeStore:GetSortedAsync(false, 3)

while true do
    -- Get the current (first) page
    local data = pages:GetCurrentPage()
    -- Iterate through all key-value pairs on page
    for _, entry in pairs(data) do
        print(entry.key .. ":" .. tostring(entry.value))
    end
    -- Check if last page has been reached
    if pages.IsFinished then
        break
    else
        print("----------------")
        -- Advance to next page
        pages:AdvanceToNextPageAsync()
    end
end

For more information, see this tutorial from Roblox DevHub: https://developer.roblox.com/en-us/articles/Data-store