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

Need help understanding data store..?

Asked by
lomo0987 250 Moderation Voter
9 years ago

I have been reading the wiki page for Data Store http://wiki.roblox.com/index.php?title=Data_store I can understand most of it. But there are parts where I don't understand and there aren't many examples that I can look at to actually see what they mean by it.

For instance, this is one of them that I can understand but also don't understand. Such as how does it actually save the newValue? on "return"?

local DataStore = game:GetService("DataStoreService"):GetDataStore("Points") 

game.Players.PlayerAdded:connect(function(player)
    local key = "user_" .. player.userId
    --we want to give 50 points to users each time they visit
    DataStore:UpdateAsync(key, function(oldValue)
        local newValue = oldValue or 0 --oldValue might be nil
        newValue = newValue + 50
        return newValue 
    end)
end)

I know that above script when a player enters, it finds the user's id and adds 50 to it. but I don't see where it would save other then on line 6.. "DataStore:UpdateAsync(key,function(oldValue)" But I don't see how it saves that unless it is the return.

I also don't know how it loads from the Data Store either. :/ If anyone could give me an example and very minimum explaining that would be great. (Or provide me a link that I can look at that explains it)

Answer this question