DataStore Across Servers

I was going to make a DataStore for coins in my game and there will be a lot of places in my game. Is there a way to have a store go across-games/places?

2 Likes

DataStores save between every place in a game. If you’re wanting to save data between separate games, then you’d need to rely on an external database.

2 Likes

A data store is stored within a game. So it would be applied to all places within the game. But it is not cross game. So you cannot have a internal DataStore within roblox to sotr data across different games. You have to use an external data base by using Http Service

1 Like

How would I be able to do that?

1 Like

That I am not too clear as I am still trying to learn http service and which site I should use to save my data. You should ask someone else specialised at this to help

1 Like

Easy use the firebase module

GameInfo.Firebase.ClanChatDatabase:SetAsync(Player.Name, {
		ModeChoosen = ModeName;
		Date = CommonUtility.GetDate():Format("#W #d, #Y: #H:#m #a")
	})


local FirebaseService = require(game.ServerScriptService.Modules.FireBaseService)(FirebaseUrl, FirebaseAuthKey)

local Database = FirebaseService:GetFirebase("")

GameInfo.Firebase = {

ClanChatDatabase = FirebaseService:GetFirebase("PlayerInfoDatabase")

}
1 Like

If you’re trying to save/load data across places within a single game, then yes, it’s possible. You would just need to get the data store that you used in all of your other places and load it in a script (so you can use those values).

Example code:

-- server script in ServerScriptService; located in all places that use the saved values

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("NameOfDataStore")

game.Players.PlayerAdded:Connect(function(player)
    -- use :GetAsync() to load player data
end)

game.Players.PlayerRemoving:Connect(function(player)
    -- use :SetAsync() to save player data
end)

If you’re wanting to access a data store between games, then I’m not sure how to help you. I do think that @TwyPlasma’s solution would be a good place to start, though.

That’s it or is there anything else?

Could I just use the same script in each place? Didn’t really explain that?

1 Like

Yes, as long as the structure of the data is the same in each place.

The way the data is handled in your game.

1 Like

DataStore won’t work.

local DataStoreService = game:GetService("DataStoreService")

local DataStore = DataStoreService:GetDataStore("CashDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder")
	folder.Name = "CoinsFolder"
	folder.Parent = player
	
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = folder
	
	local data
	local sucess, errormessage = pcall(function()
		data = DataStore:GetAsync(player.UserId.."-Coins")
	end)
	if sucess then
		coins.Value = data
	else
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local sucess, errormessage = pcall(function()
		DataStore:SetAsync(player.UserId.."-Coins",player.CoinsFolder.Coins.Value)
	end)
	
	if sucess then
		print("Saved")
	else
		warn(errormessage)
	end
end)

What does not work, getting or saving the data? Are there any errors?

I’m not sure. It seems to work now…

It doesn’t work now? I’m so confused?

Have you tried printing the data when getting it?

If you are wishing to have data tracked across different places, and not include them in one universe (wherein, you have to join a start place to reach other places) you have to use an external database and use HttpService to handle requests.
However, this can be a little daunting and challenging; learning HttpService and how requests work can be tricky, thankfully there are a few resources out there to help with this.

Linked above, was my Roblox-Firebase module, which is an API Wrapper written on Roblox to handle API requests to Firebase, it is built and designed in similar fashion to DataStoreService and thus makes transferring from DataStores to Firebases simple, and from scratch pretty easy to set up. The article covers setting up a Firebase Realtime Database, finding your unique authentication key, and contains a simple example script to get you started. It also links to the github page, and other areas of the web to provide assistance and guiding where wanted.

Using HttpService and an external database is likely the optimal solution for your problem as far as I can tell. Hope this helps!

2 Likes