I have a game that teleports you to a place inside the place. You guys know what I am talking about right? Anyways the wiki says places inside places can use the same data store but how would I go about doing this. I cant find any tutorials or anything.
Heres what ive done so far that hasent been working.
I have this data saving script inside the main place.
local DSService = game:GetService("DataStoreService"):GetDataStore("1302851773") game.Players.PlayerAdded:connect(function(player) local uniquekey = "id-" .. player.UserId local leaderstats = Instance.new("IntValue", player) local Units = Instance.new("IntValue", leaderstats) local Crystals = Instance.new("IntValue", leaderstats) leaderstats.Name = "leaderstats" Units.Name = "Units" Units.Parent = leaderstats Crystals.Name = "Crystals" Crystals.Parent = leaderstats local GetSaved = DSService:GetAsync(uniquekey) if GetSaved then Units.Value = GetSaved[1] Crystals.Value = GetSaved[1] else local NumbersForSaving = {Units.Value, Crystals.Value} DSService:SetAsync(uniquekey, NumbersForSaving) end end) game.Players.PlayerRemoving:connect(function(player) local uniquekey = "id-" .. player.UserId local Savetable = {player.leaderstats.Units.Value, player.leaderstats.Crystals.Value} DSService:GetAsync(uniquekey, Savetable) end)
And in the second place I have the exact same script. I was hoping it would work but it hasnt been. Anyone have any ideas?
Thank you for your time! :)
Ah. A game is defined as 1 or more places. Places are the levels which users can play on. Places in a universe share their datastore. Meaning you can share data across places.
What is a universe in Roblox
In the image here "Current game" represents a universe. It consists of only one start place zero or more places which you can teleport to freely. You cannot join a place directly and you will be redirected to the start place. The only way to get to a place is from the start place or another place within the same universe.
Data Store
There are only two types of data stores in Roblox OrderedDataStore which only holds integers as values in an ordered set and GlobalDataStore which can hold a variety of types but has no order to its data.
Data Stores are accessibly by any place within the universe which makes it vital that you save and get the data in the same way for all places else the data will be out or sync with others.
One method would be to use a Linked script or you could use a private module and require it with its id.
Either way you will need to think how you can make sure that the data is saved correctly for all places. It may also be useful to include a save version number ie {ver = 1, data = some_data}
to allow you to handle different versions of saved data.
I hope this helps.