I hope this is the correct category. HUGE QUESTION! I’m making a settings GUI and then I want all the values like if they disable shadows when they rejoin it saves. Where I would use a datastore… BUT FOR ALL MY SETTINGS??? That’s way too many data stores. Is there any easier way to do a datastore for ALL my settings? Since I got like 40 settings and 30 of them I want them to save which needs a datastore.
Yes there is an easier way, you should be using a single table under a single key to store each player’s data (aside from ordered data store data).
Huh, how would that look. Not sure what’s a ordered data store.
Ordered data stores are for leaderboards. If you aren’t using them then you can ignore that part.
You’d basically have a large table of key-value pairs and possibly nested tables to organize the data, then when you go to call :UpdateAsync or :SetAsync to save the data, you’d pass this table as the value to be saved. It should all be under a single data store under a single key per player.
I have multiple bool values and string values to save, could I see an example?
Yeah, so if you had them in a folder inside of the player, and this folder is called “Data”, it would look something like this:
local thisPlayersData = {}
local playerDataFolder = player:FindFirstChild('Data')
for i,v in ipairs(playerDataFolder:GetChildren()) do
thisPlayersData[v.Name] = v.Value
end
local success, result = pcall(dataStore.SetAsync, dataStore, player.UserId, thisPlayersData)
if not success then
warn(result)
end
This would make it so the names of the value objects are the indexes, and the values are the values. So something like:
{
someIndex = someValue
}
Uhhhhhh. For data stores I don’t use ipairs since they’re so confusing to me.
Here’s how I do data stores:
local DataStoreService = game:GetService("DataStoreService")
local SaveCash = DataStoreService:GetDataStore("TEST")
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Value = 0
Cash.Parent = Leaderstats
local Data
local Success, ErrorMessage = pcall(function()
Data = SaveCash:GetAsync(Player.UserId)
end)
if Success then
Cash.Value = Data
else
warn(ErrorMessage)
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local Success, ErrorMessage = pcall(function()
SaveCash:SetAsync(Player.UserId, Player.leaderstats.Cash.Value)
end)
if Success then
else
warn(ErrorMessage)
end
end)
Could I have an example using my way of making data stores? I’m bit confused also on how you would make the table and etc.
Store the settings inside a single table value and store that within a single ‘DataStore’ instance.
Could I see an example? Adding characters