Public Data Saving!

Hello, LetsGoLolyl here, and i made my first own open source module for use and modification!
This is my first module made for the public, so dont expect the best out of it :sweat_smile:

You can just get the module from this place: Crossing Data Module

[Allow Copying is on]

This module was made to share data between all servers and to save them!
Use of cases are like an exist system, which servers need datas from other servers!

This system was made by using DataStoreService and MessagingService!

So lets begin ^^

First of all lets make a script in ServerScriptService to create a public data!

  1. Now require the module and create a public Data!
    You need to enter 3 Variables into the function!
    var 1: Datastore name
    var 2 : Sync key name for the datastore, also used for MessagingService
    var 3: Updating Time, of when the new data should be sent! [minimal 10s]
--// Modules
local sharingData = require(game:GetService("ReplicatedStorage").SharingData)

--// Variables 
local publicData = sharingData.createPublic("DataStoreName", "SyncName", 10) 
  1. Now lets get the data being sent from the messagingService, that other servers are sending!
    [and we are going to use retrieveData(), this is used to get the data from dataStore, a must need]
publicData:catchData(function(data)
-- if a server sends new data, this function will then handle the data!
end)

publicData:retrieveData() -- this is used to get data from the datastore, please only use this after :catchData()

WOW! Now we created the basic public Data!

But… How to we send new data?

So!

  1. publicData:queueData()!

publicData:queueData( { ["Example1"] = 1, ["Example2" = 3] } )

Now the system is kinda hard coded, so you need to create the tables like this, but if you know scripting, maybe you can change it? But, as for basic use like exists, this should work

Now, lets say you keep your scripts organized like creating a script for creating the public data and a script changing it, and theres a way for it!

  1. getPublic is a method of getting a created public data!
getPublic = sharingData.getPublic("Testing", "ThisIsASync", 15)
-- so the first variable inside is the name of the dataStore
-- the second one the sync key, and make sure both of them are exactly the same as in the created public data!
-- the third variable is called "tries" in the module, as it may be that you are calling the datastore before it even was created, so it will try the same method 15 [variable] times, until it found the created data!

Cool, we did it!!!
Heres again a list of all of the functions you can use:

  1. .createPublic(DataStoreName, SyncKeyName, UpdateTime) --this is used to create the meta for the dataStore!

  2. .getPublic(DataStoreName, SyncKeyName, Tries) --get an already created Public Data, make sure the name of the datastore and syncKey is the same as the one from the .createPublic()!

  3. :catchData(function) -- this is used to get the data sent from the other servers!

  4. :retrieveData() -- this is used to get the data [GetASync], will also fire the function from :catchData(), thats why you need to use it after :catchData()

  5. :queueData(table) -- queue data that will be saved and send later on

:catchData() and :retrieveData() should only be used for .createPublic() and not get!!!

Any other functions inside the module is used for the system, and not for you to handle outside the module!

Tables will always look like this when sent and saved!

{
	["Example1"] = 10,
	["Kitty"] = 5,
	["Module"] = 7,
}

Hope you liked this ^^
Feedbacks will always be appreciated! :smiley:

I really recommend looking into the two scripts i created in the place, because it shows a better way how to use it [made an exist system with it]
Located In: ServerScriptService → PublicData and Workspace → Folder → Touch

If you want you can reupload this module, but only when making changes, because i think i wont change much anymore :sweat_smile:

4 Likes

Congratulations on your first public release! I glanced at the code and have some feedback:

  • This seems to have overlap with Memory Stores - is this an oversight or does your module have notable features that Memory Stores don’t have?
  • It seems a bit extreme to kick all players if a DataStore fails to load - might want to just print an error message that explains what’s wrong for the developer to handle on their own.
  • There should be a better distinction between createPublic and getPublic if you’re not able to use things like catchData and retrieveData - expectation is that I’d get something similar given the naming, but seems not.

It’s a good personal milestone to put yourself out there and make something. Good luck on this and your future projects.

5 Likes

Sorry for the late response, and thanks for the feedback! ^^

  1. I never heard of memory stores so i cant really answer this question, but my system is made so i can cross data between servers, and also save them. An example to understand this is the exist system like in pet simulator, where it would count how often a pet has been hatched globally.

  2. Yeah, i maybe rushed that a bit so i didnt thought of it :sweat_smile:The thing was just if the game didnt got the saved data before getting data from other servers would be a bit weird, so thats why i used kick, but yeah, printing would be better

  3. A naming thing, and im not the best in it. GetPublic is just a function to get an existing public data created by another script like i said in the post. Its just how you organize your scripts.

2 Likes