Saving a global value

hello, i am quite new to datastores and right now i only know how to save values to certain players. but how would i go about making a system where every time a player completes a level in my game, it will add ‘1’ completion to that level, and will save across all servers, so basically you can see how many times any player has completed a certain level.

Think on datastores as a table. A “Player” doesnt “have” a datastore. Its “one” datastore you have in game. When you save on it:

DateStore = {}
DateStore["Player_13524894"] = {Tools = {"bla", "bla"}}

You are saving stuff by using a key, and saving some data inside that key.
Just because you are using the player ID or name as the key, it doesnt mean it “belongs” to the player. Its just a table that holds a key with a number based on the player.
So you can save into datastore something like this:

DateStore = {}
DateStore["Level_1"] = {126489498, 123158947, 1231564} -- ID numbers of whom completed the level 1

You would be saving a key named Level_1, which holds all IDs that completed level one. Make sure to use UpdateAsync otherwise you could be overwritting previous data

Or (to save how many times a player completed a level)

DateStore = {}
DateStore["Level_1"] = {
	[126489498] = 8, -- times player ID completed level 1
	[123158947] = 2,
	[1231564] = 4
} 

Check documentation: Datastore, GlobalDataStore
Other methods could be using MessagingService or MemoryStoreService

2 Likes