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

How would I save it to player?

Asked by
DrGloo -2
10 years ago

I'm using DataStore.How would I make the value save to the player instead of server.Note: The Value is in the player and not a variable.

2 answers

Log in to vote
1
Answered by
Dummiez 360 Moderation Voter
10 years ago

Actually, Data Store should be rather used to store player save data as it says in the Data Persistence Wiki itself. tldr; don't use Data Persistence for anything. (Except if you're saving Instances, like models and parts)

Data Persistence is a method of saving data for games so that the data can then be loaded when the player visits the game again. Data Stores were more recently introduced and are more robust than Data Persistence and are now the recommended method of storing player data.

This is something I wrote up in a few minutes, so forgive of the rustiness. Just tell me if there is anything wrong because I haven't tested it. xD

local ds = game:GetService("DataStoreService"):GetDataStore("Score")

game.Players.PlayerAdded:connect(function(player)
    local key = "user_" .. player.userId
    local score = 0
    ds:UpdateAsync(key, function(oldValue)
        local newValue = oldValue or 0 --oldValue might be nil
        score = newValue
        return newValue
    end)
    repeat wait() until player.Character
    local stat = Instance.new("IntValue")
    stat.Name = "leaderstats"
    local ls = Instance.new("Score")
    ls.Value = score
    ls.Parent = stat

    stat.Parent = player

end)

game.Players.PlayerRemoving:connect(function(player)
    local key = "user_" .. player.userId
    ds:UpdateAsync(key, function(oldValue)
        local newValue = player.leaderstats["Score"].Value
        return newValue
    end)
end)
Ad
Log in to vote
0
Answered by
Nickoakz 231 Moderation Voter
10 years ago

You would use Data Persistence, not data store to save to a player instead of the server. http://wiki.roblox.com/index.php?title=Data_persistence

0
But Ive seen this done before DrGloo -2 — 10y
0
Anyone DrGloo -2 — 10y
0
Im so lonely :C DrGloo -2 — 10y
0
No one loves me DrGloo -2 — 10y
View all comments (2 more)
0
Anyone knows how? DrGloo -2 — 10y
0
ANYONE? DrGloo -2 — 10y

Answer this question