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

How do I use Data store to share data between two places?

Asked by 6 years ago

If I used data store to save a value in one place, how would I get that saved value in the other place?

Data Store script in the first place:

local quirkstore = game:GetService("DataStoreService"):GetDataStore("Quirk")

game.Players.PlayerAdded:connect(function(plr)

    local stats = Instance.new("IntValue", plr)
    stats.Name = "leaderstats"

    local quirk = Instance.new("StringValue", stats)
    quirk.Name = "Quirk"
    quirk.Value = quirkstore:GetAsync(plr.userId) or ""
    quirkstore:SetAsync(plr.userId, quirk.Value)        

end)

game.Players.PlayerRemoving:connect(function(plr)
    print("Saving Player Data")
    quirkstore:SetAsync(plr.userId, plr.leaderstats.Quirk.Value)
    print(plr.leaderstats.Quirk.Value.." Has been saved")


end)
0
If you are talking about different places that aren't a part of the same Game (There is a difference between these) you cannot access the data store. If they are in the same game, you would simply connect to the data store the same way you did in this script. MrLonely1221 701 — 6y

1 answer

Log in to vote
0
Answered by
gitrog 326 Moderation Voter
6 years ago

If the places are part of the same game, you can simply use the same DataStore name and it will go through. Just put the same script in the second place if they aren't.

0
Ah, Okay I get it. Thanks! roblox99456789 104 — 6y
Ad

Answer this question