How do I fetch/organize information in my module scripts?

You read the title… I’m pondering what method would be the best performance wise and cleanest in my module scripts. I’ve been researching _G and shared but I’ve seen support and criticism on both sides on whether its efficient or not.

Firstly, I think I need to explain the scope of my module scripts. I’m not sure if I’m doing this efficiently or if I’m making a major mistake but I’ve noticed that some things that are bringing down the performance (speed) of my module scripts… I think. My explanation may come off as vauge… just bear with me…

Storage method

There are stats (string value instances with attributes attached to them) which are located inside of ServerStorage. These are essential to the module scripts, since most of the functions inside of said module scripts revolve around retrieving these stats multiple times. I should also note that the client is the one who is running these module scripts- I don’t know if thats a problem, but whenever I run the module scripts on the client it seems WAY faster than the server and I like that. Also animations playing and animation event functiosn are way more accurate on the client.

Retrevial method

To get these stats, I have functions inside of the module script which find the afformentioned stats from eariler from given criteria. Usually, they’ll have to fire a RemoteFunction from client to server in order to get it, which I feel like is the crux of the problem. I don’t think this is relevant but on each of these retrevial functions I have a if runService:IsServer() elseif runService:IsClient() end or vise versa on each of them. These stats will then be used in both calculations via the server or appearences on the screen when you click buttons via the client.

Yet again, I was debating between using _G and or shared, but I’ve seen grand controversy surrounding each. Should I cut back on remote functions or something? It seems to not be working fast enough. Please let me know.

P.S. I may follow up with a question on how to optimize further things if you’re up to it…

P.S. P.S. If you need further or clearer explanations on certain things I’ve said, just say so because I was like half asleep writing this and I can’t tell if I’m ingenius or retarted in my explanations.

1 Like

Hi, non-believer of _G and shared here :raising_hand_man:

You list two methods, but likely what matters more here is context. These “stats”… Are they constant values necessary for both the client and server to know? If so, then you’re likely best off just having a ModuleScript under ReplicatedStorage. No need to check whether it’s the client or the server asking for the stats. Under most circumstances RemoteFunctions should only be used when you need to get some value from the server that the client can’t determine itself.

Provide additional context if you’d like to follow up.

1 Like

Ok, sorry for the late reply but the context here is I’m attempting to make a turn based RPG, so the stats are pretty much constant until you do something to change them, like dealing damage for example.

So, just don’t use _G and shared?
And also- I’m storing these stats in ServerStorage so the stats are only accessible to the server so the client has to either fire a RemoteEvent or Function in order to tap into them, should I just move them to ReplicatedStorage or will exploiters be able to mess with them?