LuckyDataStore - An Easy to Use Saving Module with Session Locking and Auto-Saving

Hello! I made a configurable module that saves your data, has session locking and auto-saving system.

There are some things that I would like to point out,

  • Module ID has been changed due to me being unable to update the old model.

  • In the last version (v.3.0.1), session lock has been tested with numbers. Changing someones currency then they rejoin so fast (about 2-3 seconds), module waits until old data has been saved, if it is not then module will not load data until old data gets saved or 30 minutes passes.

  • Module will automatically fill data if it doesn’t exists. For example if you only had “Money” on your default values and you add more onto it, for example Experience, module will automatically add Experience to the data and put it is default value.

  • Editing players variables will automatically update table. However editing table will not change variables value.

  • When getting and updating player data and auto-saving, module will wait until there is enough budget to prevent Data Stores from filling the queue, however module will not wait in BindToClose function and will try to save data as much fast as possible because Roblox gives servers 30 seconds until they really shutdown.

This module is still work in progress, bugs may occur. If you encounter any bugs or errors please let me know. This is not the final result and everything is up to change.


LuckyDataStore v3.0.0 is here with Session Locking!

Check update log for more info.


Contact: Zepheria#2693

Update Log: LuckyDataStore - Update Log
API / Documentation: LuckyDataStore - API / Documentation
Source Code: LuckyDataStore - Source Code
My Portfolio: Zepheria's Portfolio [Scripter]


LuckyDataStore [Open Sourced!]
https://www.roblox.com/library/7239753643/LuckyDataStore


Example Code
local LuckyDataStore = require(7239753643)

local default = {
	Money = 100,
	Experience = 0,
	Rank = "None",
    Tools = {}, -- Tables should not be used on the combine function as they are not a variable.
}

game.Players.PlayerAdded:Connect(function(player)
	
	local folder = Instance.new("Folder")
	folder.Name = "leaderstats"
	
	local money = Instance.new("IntValue",folder)
	money.Name = "Money"
	
	local experience = Instance.new("IntValue",folder)
	experience.Name = "Experience"
	
	local rank = Instance.new("StringValue",folder)
	rank.Name = "Rank"
	
	local playerData = LuckyDataStore.CreateData(player,"Test",default)
	playerData:Combine(money,experience,rank)

    folder.Parent = player
end)

Module will save when player leaves and when auto-save happens, script is meant to be basic to use for everyone!

Please let me know if there is any issue with the source code or if you have any suggestions.

Have a great day!

32 Likes

This is a really amazing module! Since you can save your data SO SO easily!

But still I’ve a question. How do you use the

GetDefault(value, 0 -- [[ What is this number?]])
GetData(value, value, value -- [[ What are these values?]])

local Key1 = DataStoreModule.Key == "Key1"
local Key2 = DataStoreModule.Key == "Key2"

--[[
    Can we do this?
]]

These are my normal questions. Will be really appreciated if you could answer these! Thanks!

4 Likes

Hello, thanks for your reply!

GetDefault is a function that you send the variable and its default value.

local money = Instance.new("IntValue",folder)
money.Name = "Money"
DataStoreModule:GetDefault(money,100)

In here, money is the variable that we just created and it will be 100 for default when a new player joins.

DataStoreModule:GetData(player,money,experience)

GetData is also another function and you need to put player instance first and then all your variables that you want to be saved. Which are money and experience here.

I still didn’t added a support for more keys but I will in the future as this module is still basic.

Again, thanks for your reply and if you have more questions, feel free to ask!

4 Likes

So, if I keep the number parameter blank (meaning I don’t put anything there) it will be 0?

Edit: Happy to see a game:BindToClose function by default on the module, so others won’t need to do it manually!image

4 Likes

You have to define a value in there because you may need to use bool values as their value is true/false and string values which their value can be anything.

Yes, I added game:BindToClose function to the module because i want to make the script easier.

5 Likes

Yea, saving bool, string, int values are also a thing so yea.

But I could make a warn statement you know? Like if I do this in the :GetDefault() function

if value:IsA("BoolValue") -- [[ Assuming the parameter is called value inside the module]] then
    
elseif --[[ Then more stuff]]
end
4 Likes

So if variable is a int value and user left the default value blank, you want it to automatically become 0, am I right?

3 Likes

Yep! I might talk to you privately later about this!

3 Likes

Okay! I already added it to the module, going to publish it in a bit.

3 Likes

DataStoreModule v1.1 is here!

  • Optimized/cleaned the module.
  • Added a new value “SaveInStudio” which enables or disables studio saving.
  • Now GetDefault(value_variable, default_value) function could be used without giving it a default_value and script will define variables default value.
3 Likes

I’d recommend marking it as solution since there will be a lot of comments lol

3 Likes

Why should we use this over ProfileService or Datastore2, which is easier to use, more advanced, less data loss, etc. Auto-saving systems are always a problem. You should NEVER Use them, as they are prone to data loss, and it’s just lazy.

2 Likes

This is a “basic” module as in the name of the post, this is just done for beginners as using data stores are not that easy for them. They may exceed the limits of data store or can’t save data etc. This is made to help those people and you are able to disable auto-save if you don’t want it, also I’m not forcing anyone to use this so if you don’t want to use it then don’t.

5 Likes

Yes, but this module has a lot of edge cases and doesn’t do much to protect against data loss except for some few basic features which are incredibly easy to implement. As far as easy ness to use goes, DataStore2 is far easier to use for beginners and is much better than this as it at least protects against some sort of data loss, this doesn’t do to protect against against such data loss and is overall completely useless.

You are essentially trying to trap beginners over using this module which is bad and useless, when they can simply use a much better one.


This module has a lot of flaws from looking at the source code, doesn’t even utilise BindToClose properly and saving calls will almost be dropped when server shuts down. I highly discourage anyone from using this module.

7 Likes

I know that it is still not that much good and I’m still working on it. It is still “basic” but while I work on it I will make more protection about data loss and hopefully backups to revert when something bad occurs.

Why I would want to “trap” players? I said I’m still developing it and I know it is not the best.

4 Likes

If it’s basic, why make it as a community resource in the first place? Anyone can implement a very basic data store easily just like this, and there are a lot of resources over data stores.

4 Likes

[quote]This module has a lot of flaws from looking at the source code, doesn’t even utilise BindToClose properly and saving calls will almost be dropped when server shuts down. I highly discourage anyone from using this module.

Instead of saying this, why don’t you help me improve it? Your just trying to make the module look bad.

I said on the post that if there is any issue or suggestions, let me know.

3 Likes

I changed it because you said that it should not be on community resources. Where should it belong?

1 Like

No no, because you said that it could be bad using this module, I changed it so people won’t use it until I add more onto it.

And instead of saying the source code is bad or don’t use the module, tell me where I am wrong.

1 Like

This module isn’t as good as other modules for example DataStore2 or ProfileService, yes I agree with that. But it just shows that it’s “Basic” meaning it probably has bugs, glitches and more. Since beginners to DataStore cannot just yet learn about DataStore2 or ProfileService since they are a little bit more difficult to understand, I’ll say this module would be really good for them!

4 Likes