Introduction
Hello, fellow developers! Many of you may use DS2 (DataStore2 by @Kampfkarren ), and find that sometimes it can be a bit confusing. I myself was confused at first, but then I got used to how it works. Still, for many of you, it might be hard to use.
Well, I believe I have a solution. A solution to solve all of your combinings, and whatnot. A solution, that will save you countless hours of debugging things. A solution, so great that it will blow your socks off!
maybe that’s too much glorification
Behold, DS2Handler! A brand new module, that combines, saves, and does everything you would want to with DS2, all in 1 module! Made simple, easy to use, and very convenient! All you have to do is require the module, and use a few basic functions!
e.g
Usage
Let’s say we want to save some coins to a player. First, let’s get the module. Insert the module into ServerScriptService
, then open it up, and do the following to set up the module. Now, upon opening the module, you should see something like this:
local Names,Defaults = {
},{}
This is where we’ll put the names of the values/datastores we want to save, under 1 datastore. Put simply, we want to store a bunch of data under a data key, kind of like storing a bunch of items into a safe. Now, there’s no need to overthink this, so all you need to do, is this:
local Names,Defaults = {
{
combineKey = "mainData", -- The key that we are storing our data under
["coins"] = 10, -- The name and default of the data,
},
-- This is the format that you will be using to make a
--new datastore value, you can also add more by inserting a name and default
-- e.g ["exp"] = 10
}, {}
Next, insert a script into ServerScriptService
, and write the following into it:
local SSS = game:GetService("ServerScriptService") -- Define ServerScriptService
local DS2Handler = require(SSS:WaitForChild("DS2Handler")) -- Get the module
Now, whenever we want to add coins/whatever currency you want, all we have to do is run this:
DS2Handler(
"Increment", -- action
"coins", -- the name of the value we want to change
player, -- the player
100 -- the amount, put a - behind it to subtract amounts. eg -100
)
Conclusion
That’s about it! Simple as that. Data will automatically save when the player leaves, so you don’t need to do anything with PlayerRemoving
or anything like that. Listed below are all functions you can use. Please tell me what you think, report any bugs you might find, thank you and enjoy!
Documentation
DS2Handler(
<string> "Increment", -- the action
<string> "coins", -- name of the value/datastore we want to change
<Player> player, -- the player
) -- Increments the value of the specified datastore
DS2Handler(
<string> "Get", -- the action
<string> "coins", -- name of the value/datastore we want to get
<Player> player, -- the player
) -- Gets the value of the specified datastore
DS2Handler(
<string> "Set", -- the action
<string> "coins", -- name of the value/datastore we want to set
<Player> player, -- the player
<number> 100 -- the value we want to set "coins" to
) -- Sets specified data store to specified value
DS2Handler(
<string> "GetTable", -- action
<string> "coins", -- name of the value/datastore we want to get
<Player> player, -- the player
) -- Use this when you want to get the value of something that is stored in a table, aka {}
DS2Handler(
<string> "OnUpdate", -- action
<string> "coins", -- name of the value/datastore
<Player> player, -- the player
<function> callback -- function called when datastore is updated, passes 1 argument which is the new value of the datastore
)
Links
Source: DS2Handler Source Code - Pastebin.com
Roblox File: DS2Handler - Roblox