Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

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.

1 answer

✓ Accepted answer

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.

1 comment

0

Ah, Okay I get it. Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.