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
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!
- 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)
- 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!
- 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!
- 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:
-
.createPublic(DataStoreName, SyncKeyName, UpdateTime) --this is used to create the meta for the dataStore!
-
.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()!
-
:catchData(function) -- this is used to get the data sent from the other servers!
-
: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()
-
: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!
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