So, I have a shop where you can buy abilities, but I have no idea how to save abilities that the player has bought. I thought of inserting a boolean of every ability there is into each player, and just save the abilities that they have, but that would be too ineffiecient once more abilities are added. I also thought of using tables that would be saved and adds an ability to it whenever an ability is bought by a player, but I have no idea how to implement that. How would I go about doing this?
Store all the abilities as a folder of BoolValues parented to each player.
I mean… that was my original plan, as I mentioned. Will it be inefficient an cause a lot of lag if there are many booleans in many players?
Don’t do this. Have a data system on the server (storing player data in an object) and then replicate it with remote events or something like ReplicaService.
If you’re planning to save data with tables, perhaps you could:
Create an empty table in a ServerScript, and connect the PlayerAdded function such that it adds a key for the ID of the Player, and creates another table as the value to another table storing the actual data, like:
-- I'm assuming you're using DataStoreService to save the data.
local dataStoreService = game:GetService("DataStoreService")
local toolData = dataStoreService:GetDataStore("InsertDataStoreName")
local itemDataTable = {}
local deafultData = {
["Tool1"] = false
["Tool2"] = false -- So on and so forth...
}
game:GetService("Players").PlayerAdded:Connect(function(Plr)
local plrUserId = Plr.UserId
itemDataTable[plrUserId] = deafultData
local joinedPlayerData = toolData:GetAsync("InsertHowYouSavePlayerData")
if not joinedPlayerData or joinedPlayerData == nil then
return
else
for i, v in pairs(joinedPlayerData) do
-- Set each value in the Player's table in-game to the values of their corresponding keys in the table in joinedPlayerData
end
end
end)
This is just a rough script to give you an idea of what to do.
Why would it cause lags?
Value instances only take memory, they’re not visually rendered in any way so they won’t cause lags.
An idea with saving players’ data in an object and then replicating it will allow you to save little memory at cost of less readable code.
What do you mean by storing player data in an object? I don’t really understand.
Use datastore service. A better alternative is profileService (not a native service). Use module scripts for modular systems which are better than using just scripts.