Hello developers!
I would like to introduce you NatureStore, the new datastore module.
What is NatureStore?
Nature store is a modulescript. It’s lightweight and easy to learn for beginners and intermediates.
It’s mainly made for intermediate devs though.
Why NatureStore?
Well, that’s a very hard question, because there are a lot of other modules out there (DataStore2, ProfileService, etc.), why is NatureStore better?
First of all, NatureStore is not better than any of these. But you may find it more logical, easier or powerful. I recommend it if you want to implement Datastores fast into your game. Also it’s easy to use even when there are complicated data structures.
How does it work?
There are a lot of things NatureStore can do.
Here’s an example code, but you can view the API on github!
Example code
local NatureStore = require(game.ServerStorage.NatureStore) -- Require NatureStore, I suggest to put it in ServerStorage
NatureStore:SetTemplate({
Coins = 0;
Time = 0;
Rank = "Noob";
}) -- We *must* create a template. These are the things we want to save for every player. In that case, it's Coins, Time and Rank
--[[ You can set default values in the template. If the player doesn't have saved data yet, those values are automatically
going to be applied (in this case, it's zero for both)]]
NatureStore:AutoLeaderboard() -- Automatically displayes loaded data on a leaderboard
game.Players.PlayerAdded:Connect(function(plr)
NatureStore:Get(plr.UserId) -- Load the player's data (you must use UserId!)
plr.Chatted:Connect(function(msg)
if msg == "yes" then -- If a player says "yes" we give them five coins
NatureStore:IncrementData(plr.UserId, "Coins", 5) -- Here we increment the Coins of our player by 5
end
end)
spawn(function()
while wait(1) do
NatureStore:IncrementData(plr.UserId, "Time", 1) -- Here we increment the Time of our player by 1
end
end)
--NatureStore automatically saves data when the player leaves, but you can save data of a player manually
--using the following function:
NatureStore:ApplyPlayerData(plr.UserId)
--or you can save every player's data, like this:
NatureStore:ApplyAll()
--If you want to disable autosave just call this function:
NatureStore:DisableSaveOnLeave()
end)
Get NatureStore!
You can get NatureStore from the library:
or you can copy the code from github, and paste it into a modulescript See source code here
One more thing
I work really hard on these projects.
If you could support me, you would make my day!
Please Share your suggestions, and report any bug in the replies!
I added a small extra to “AutoLeaderboard”, I hope you like the concept and you’ll add sg similar to the “official” NatureStore
The idea:
After defining the Datastore keys (SetTemplate) and before calling “AutoLeaderboard” function, we can define a dictionary, selecting the keys to be shown on Leaderboard.
I added some lines to the NatureStore module that handles this change (I can copy the code here if you wish)
In this way we don’t have to put all Datastore keys on the board.
If user doesn’t define onLeaderboard dictionary, all keys will be shown (as it works now).
If the user defines this dictionary, he/she can choose true or false to enable/disable keys.
Anyway, thank you for sharing this great module, it makes handling Datastore in games extremely easy!
Easy reference to the store based on UserId is the most logical way to do this and I still don’t understand why the other most popular script (2) doesn’t do that. (Once you understand the logistics of the other, you can work around it… But why have to work around it! It should be more natural.)
NatureScript is very similar to a custom solution I had previously created with the template.
One suggestion from what I ended up doing … I added a “version” requirement to the player template that should be incremented each time you update the player template table… because let’s face it… these things always change and expand over time. Having versioning allows you to more easily manage upgrades to the playerTemplate over time as you can check the player’s stored template version again the current version and take them through any needed backend upgrades or updates. (I suggest YMD.NNN format for the versioning… IE: 20211213.001 )
NatureStore:SetTemplate({
Coins = 0;
Time = 0;
Rank = “Noob”;
Version = 20211215.001;
})
Anyway – this is great community project, hope to see it continue!
I have another script that adds coins when you click on a part. The script for that is inside a click detector that is inside the part. here is the script for that:
local NatureStore = require(game.ServerStorage.NatureStore)
script.Parent.MouseClick:Connect(function(plr)
NatureStore:IncrementData(plr.UserId, "Coins", 5)
end)
I have an error that says “[NatureStore Error] Can’t save data due to an issue!”
It adds the coins just it doesn’t save.
Sorry for the trouble
As I know, there was a bug with saving on player leave. Be sure to download the most recent version.
Another possible reason that “API services” is not enabled for your project in Studio.
Go to game settings / security / Enable Studio Access to API Services and set it to True.
To test, try to add a “manual save” line:
NatureStore:ApplyPlayerData(plr.UserId)
As Apafey said.
Check if you have the latest version (you can see the version in the modulescript, the latest one is the 15 Dec)
Also make sure to Enable Studio Access To API Services
This is a resource that has data saving methods worse than ProfileService but functionality better than ProfileService.
You have essentially the same concept as ProfileService with your saving method (creating a table that stores data and whatnot). My question to you is why not take ProfileService, utilize it’s data saving methods (while obviously making sure to credit the github and its contributors MadStudioRoblox/ProfileService: Universal session-locked savable table API (github.com) ), and then proceed to add your custom functionality to it?
This is a universal compromise and a win-win for everyone. ProfileService’s name and contributors gets spread even more, your module becomes 10 times more reliable for data saving and all of this at no expense to any of the parties involved.
Just be sure to double check with Mad Studio (or loleris considering he’s the lead developer) if they are okay with permitting you to use ProfileService in this case.
To be honest, I don’t understand how ProfileService works.
I’m really bad at understanding other’s codes, that’s why I don’t want
to use ProfieService as a “base code”.
But, if there’s anything I could implement to make NatureStore more reliable, please let me know!