DatastoreX
Work faster and better with datastores!
This module is inspired by DataStore2!
Hello everybody!
I was tired of having to code too much when working with datastores.
So, I developed a faster mode to work with them!
DataStoreX is a module to make working with datastores faster and also create backups!
Example code:
local DataStoreX = require(game.ServerScriptService.DataStoreX)
local Coins = DataStoreX.connect("coins")
Coins.set({
"Xsticcy" = 1000;
"OtherPlayer" = 2000;
"CoolGuy" = 1500;
})
Tutorial
Of course this plugin can do more than you see in the example!
In this tutorial you will learn to use DatastoreX!
See tutorial
1) Setup the module
Once you downloaded the module from the library,
put it into ServerScriptService!
2) Connect to datastore
Create a Script in workspace for example
Open up the script and write the following line of code:
local DataStoreX = require(game.ServerScriptService.DataStoreX)
Next, we are going to connect to a datastore.
To do this write:
local testDS = DataStoreX.connect("TestDatastore")
3) Set keys
Now comes the fun part.
Unlike normal datastore, in DatastoreX you can set multiple
key’s value at once
This is pretty easy to do:
local testDS = DataStoreX.connect("TestDatastore") --connect to datastore
testDS.set({
"TestKey" = 10;
"TestKey2" = 20;
})
The following code will create two keys (named TestKey and TestKey2) and set
their values (TestKey’s value to 10, TestKey2’s value to 20).
If the keys already exists, then they value will be replaced to the new one.
4) Get keys
This is very similar to set.
You can get multiple key’s value at once!
local testDS = DataStoreX.connect("TestDatastore") --connect to datastore
local values = testDS.get({"TestKey", "TestKey2"})
print(values)
print("TestKey's value is:", values.TestKey)
You need to give a list of keys you want to get.
(Output:
{
["TestKey1"] = 10,
["TestKey2"] = 20
}
)
5) Remove keys.
Works the same way as get.
local testDS = DataStoreX.connect("TestDatastore") --connect to datastore
local values = testDS.remove({"TestKey", "TestKey2"})
You need to give a list of keys you want to remove.
(Now you know the basics, but there’s more!)
6) Backups
Yes, you can create backups too!
local testDS = DataStoreX.connect("TestDatastore") --connect to datastore
local values = testDS.createBackup({"TestKey", "TestKey2"})
You need to give a list of keys you want to backup.
But what’s the point of backups if you can’t get them?
Of course, you can!
local testDS = DataStoreX.connect("TestDatastore") --connect to datastore
local values = testDS.get({"TestKey", "TestKey2"}, true)
If you give a second parameter (and set it to true) when getting keys then
if the key’s value is nil then the module is going to look for the value
in the backups.
7) setAll
With setAll you can set multiple key’s value to x.
For example:
local testDS = DataStoreX.connect("TestDatastore") --connect to datastore
local values = testDS.setAll({"TestKey", "TestKey2"}, 120)
You need to give a list of keys you want to set.
And for the second parameter, you need to give the value.
8) increase and decrease
With increase you can increase multiple key’s value by x.
For example:
local testDS = DataStoreX.connect("TestDatastore") --connect to datastore
local values = testDS.increase({"TestKey", "TestKey2"}, 10)
You need to give a list of keys you want to set.
And for the second parameter, you need to give the x.
Same with decrease:
local testDS = DataStoreX.connect("TestDatastore") --connect to datastore
local values = testDS.decrease({"TestKey", "TestKey2"}, 10)
9) Caching
When you set/get a key’s value, DSX is going to save it into a variable.
For example:
local testDS = DataStoreX.connect('testDS')
testDS.set({
"Key" = 10;
})
--do stuff
print(testDS.Key) -- output: 10
9+1) Rules
This is an extra feature that can be useful sometimes!
I will show one example code:
local testDS = DataStoreX.connect("TestDatastore") --connect to datastore
local values = testDS.get("@[TestKey&1-5]") -- the rule is: @[TestKey&1-5]
This will get the value of TestKey1,TestKey2,TestKey3,TestKey4 and TestKey5.
You can just memorize the syntax and change the numbers and the text.
Let me show you more rules:
@[Player&1-10] -- get the value of: Player1, Player2, ..., Player10
@[Building&5-20] -- get the value of: Building5, Building6, ..., Building20
@[Save&1-5] -- get the value of: Save1, Save2, ..., Save5
I hope you can understand the syntax now.
You can use rules in the following functions:
setAll, remove, get, createBackup, increase, decrease
Other things made by me(Xsticcy)
[OPEN-SOURCE] Free Data Editor plugin!
When working with datastores, it sometimes hard to see what are you doing and what is the value of the keys. I recommend Data Editor!
I would be pretty happy if you support me: Support my work! - Roblox
Get the module
Share your problems, ideas and feedbacks in the replies!
Goodbye!