I am creating a prison game and need help with organization in player and more. By the time the game is done, the player would have over 30+ values inside it to create checks and stuff, but when I try to update the game again other scripters including myself would be EXTREMELY confused. I have asked another question similar to this here: https://devforum.roblox.com/t/value-organization-help/339281/4
but it seems that I have to make the dictionary global, in order to store all the player values which I heard and believe is bad practice and unorganized. How would I try to organize everything in the player(mostly values like isInnocent, officerWarnings, etc)? Should I group the values and try to organize them that way(folders don’t work because they would insert a leaderboard)? If you have game creating experience, please tell me how you organize everything.
Actually, you should use a map of all these values and put the Player’s name as the key and another map to put the officerWarnings and all those values in them.
local module = {}
local playerMap = {}
function module.setKey(keyName, value)
playerMap[keyName] = value
end
function module.getKey(key)
return playerMap[key]
end
function module.getKeys() -- iterate through this one with a for loop
return playerMap;
end
return module;
Yes you should use modulescripts, they cache the data so you don’t have to use something insecure like a global table, and you can put the module in the serverstorage and use remotefunctions to get them from the client, so exploiters can’t edit the values.
Just a note, exploiters shouldn’t be able to edit ValueObjects in their player anyways (well they can edit it but it just wont replicate to the server)
tbh I prefer using value objects in the player for small things like Gold, exp, stamina so they don’t have to invoke an RF to the server and I can use it in gui easily
It’s the best way to do that, here’s an example:
-- Server
RemoteFunction.OnServerInvoke = function(Player, Key)
for _, value in pairs(module.getKey(player.Name)) do
if value == Key then
return value
end
end
end
If you want to know when something has changed, fire a bindableevent, it works like a remoteevent except it’s e
replicated across two server/client scripts.
Nope, you won’t have to use too much performance, it MIGHT be a little bit more than values, but doing this is more common and you should familiarize yourself with ModuleScripts.