Helloo,
I was making a saving system with the DataStore, and I realised I have quite a lot of data. So far, I was storing the data as “intValue” and “stringValue” and so on inside the player, but I was wonder how could I do it better with moduleScripts, and use tables. And here are my questions:
My first question is, if I was to use a moduleScript as a way to store data, should I make one for all the players, with the indexes being the players name, or a moduleScript for each player, that would be stored idk like inside of the player.
My second question is, if I was to make just a moduleScript to store the whole data for all the players, where would I put it? In ReplicatedStorage or in ServerStorage and make the values changeable thru RemoteEvents?
Thank you, any additional information and tips are highly appreciated! <3
Make an individual module for each player, I would recommend storing them in ServerScriptService. Remember to destroy them when the player leaves. It would be better for accessibility than an Object-Oriented system.
You should make a remote function to retrieve data, but do not let the client use an event to directly modify the data. It will be very exploitable. Instead, modify on the server and validate any data needed from the client.
Well, you might have a remote, and then validate it. In the module you might have a method to update it:
local inv = {}
inv.__index = inv
inv.Data = {
["Money"] = 0
}
function inv:Update(stat, new)
self.Data[stat] = new
end
return inv
local function update(player:Player, statType:any, newStat:any)
--do some checks on the new stat here or something
--I can't give an example cuz idk what ur game is like
local inv = require(path_to_folder[player.Name])
inv:Update(statType, newStat)
end
someRemoteEvent.OnServerEvent:Connect(update)