Hello! I am PLA_Yd a chronically online dude that likes to do Roblox Studio, just like you guys!
You know what I hate? Datastores. So freaking annoying to get working and I don’t like messing with tables. But fear not, friends, for I have a solution!
I created a datastore script that utilizes DataStore2 to store data using folders and values (such as bool and number values)
Here is how it works:
All folder within the “Plr” folder inside the script will be added to your player upon joining. Then, values within these folders can be changed by any server script and will be saved automatically!
For example, you can make a folder called “ownedItems” and then make a bool value called “sword” inside it. If the bool value is true, that means the weapon is owned by you and it would save!
Also, I believe that DataStore2 also makes backups of data, so that’s a plus!
The actual script is only 40 lines of code, so you can also read the code to understand how it works.
-- PLA_Yd's Datastore Script
local DataStoreService = game:GetService("DataStoreService")
local players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local pF = script:WaitForChild("Plr")
local dsM = require(script:WaitForChild("DataStore2"))
--CONFIG:
local mainKeyName = "quickStoreDefault" -- Name the datastore whatever you want!
local keyTable = {}
for i, folder in pairs(pF:GetChildren()) do
for i, item in pairs(folder:GetChildren()) do
table.insert(keyTable, folder.Name.."_"..item.Name)
end
end
dsM.Combine(mainKeyName, table.unpack(keyTable))
players.PlayerAdded:Connect(function(plr)
for _, folder in pairs(pF:GetChildren()) do
if folder:IsA("Folder") then
local fc = folder:Clone()
fc:ClearAllChildren()
fc.Parent = plr
for i, item in pairs(folder:GetChildren()) do
local new = item:Clone()
local itemStore = dsM(fc.Name.."_"..item.Name, plr)
local defaultVal = item.Value
new.Value = itemStore:Get(defaultVal)
new.Changed:Connect(function()
itemStore:Set(new.Value) --When the data changes, it sets the data
end)
new.Parent = fc
end
end
end
end)
Here’s the issue. You’re expected to wrap Datastore2, ProfileService, and other modules like that, for each game. It would accommodate for the game’s needs, such as managing coins and gems, and tries to prevent the developer from accidently corrupting the user’s data.
This resource is another one of those wrappers, but it’s generic. Generic wrappers are good for beginners, but they don’t provide much value when making an actual game. You’d need to make your own for it to be useful to you.