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

Leaderboard Problems. Leaderboard not saving or loading correctly? (Data store difficulties)

Asked by 9 years ago

I've made three scripts, one was a leaderboard script, another was save and the final was load. The leaderboard script worked fine except when it came to the save and load scripts, they weren't showing errors but when I loaded the game, they would load to a save I did almost 5 minutes before that. Here's the code: Save Script

local DS = game:GetService("DataStoreService"):GetDataStore("PoloBear_PP")

game.Players.PlayerRemoving:connect(function(player)
    local pointsToSave = (script.Parent.Parent.leaderstats:FindFirstChild("Promotion Point").Value)
    DS:SetAsync("pp", pointsToSave)
end)
game.OnClose = function(player)
    print("Finishing final tasks")
    wait(10)
    print("Done")
    end

Load

local DS = game:GetService("DataStoreService"):GetDataStore("PoloBear_PP")

game.Players.PlayerAdded:connect(function(player)
    wait(10)
    local savedPoints = DS:GetAsync("pp")

    if savedPoints then
        script.Parent.Parent.leaderstats:FindFirstChild("Promotion Points").Value = savedPoints[1]
    else
    local valuesToSave = (script.Parent.Parent.leaderstats:FindFirstChild("Promotion Points").Value)
    DS:SetAsync("pp", valuesToSave)
    end
end)

It's working but I'm trying to make it, so if you switch servers it will still be there, I don't want a delay is just the problem, I'm not sure if it is because its a one person server if that's the reason why or if it's not loading correctly.

0
Try using UpdateAsync() it creates/saves/replaces data for the user; but it only takes half the work here. ;D http://wiki.roblox.com/index.php?title=UpdateAsync MessorAdmin 598 — 9y

Answer this question