Help on creating server sided data where players can access

I didn’t find a better title.

Time ago i have started to create my own shop, well, in that time, the shop data was a ModuleScript in ReplicatedStorage, well, i thought about hackers changing the data inside the script, so they can get stuff for free or anything else, so i thought about changing the module to ServerScriptService, and now i got the problem that clients can’t access to ServerScriptService, i don’t know what i could do, i don’t have the code right now, here is a code of reference that i have written before: Attempt to index local 'PetData' (a nil value), It’s a bit outdated, but that can help you more (in the script, ShopData is the module that contains the shop data, the second script is the module and how data is stored as an example.)

What i have tried to do is use Remote Events, but hackers can fire the event for other players, to crash their devices. I don’t know what i could do, thanks for reading.

1 Like

This shouldn’t happen.

What you can do is use a RemoteFunction so the client can request the data (only read, never write) whenever necessary.

As far as I remember a modulescript cannot have it’s variables/data changed once they’ve been assinged. Your module assumably only returns data to the shop. Exploiters won’t be able to modify this data unless you’re for some reason storing it somewhere where they can edit this to trick the shop system.

Modules return only once per machine so if you modify a modules table in one script on server it will change for all other scripts that use the same table.
This does not mean that information will replicate though (unless you code the module so poorly that clients can manipulate whatever they want on it with remotes)

1 Like

It’s possible to send the entire shop data in the function?

@NewPuncher Well, you can change Modules data with scripts.

I’ve been told. I just feel like I remember reading somewhere that you couldn’t. Must have been something else. Surely though they would need to know the functions inside the module that return the data in order to actually change anything.

1 Like

I mean you can but it really should not be necessary. You can have a lineup of contents organized in some place like replicated storage since the client would need access to it at some point anyways. Moving stuff into SSS just means its more complicated to communicate to the client and give them what they need. Really not worth the effort imo. Just make it so the client already has all the information it needs and can request something like save data for example, then it should pretty much just communicate like this afterward:

returnCode = shop:InvokeServer(shop.ITEM_BUY, item.Id)

How would i do that? Sadly, i don’t know what do you mean.

In my games, I have modules containing information that is used in both the client and server pertaining to the shop, as well as all items neatly organized and categorized into folders where both of them can access them. This way, managing and dealing with the store and store items becomes really easy.

So, what you are trying to say is that i could use two modules? (One in the Server and another in the Client)

You can use the same exact module if you like. Usually I use the same one and if I need to change what happens on the server vs the client, I just use some script “macros” that arent really macros.

local RunService = game:GetService("RunService")
local SERVER = RunService:IsServer()
local CLIENT = not SERVER --just for naming purposes i guess

--add shared properties and values
--i.e. classes you create, paths to objects, and properties

if SERVER then
--put some functions in module
--i.e. add handlers for client communication
--put other functions in module
--i.e. add handlers for server communication

This way I can make sure that both of them have the same handlers like item.Id, know where the items are, provide functions to get and deal with them, etc.

You can also of course separate this into multiple modules, one with the basic shared information, and one without (server/client specific), but I like this design because it is easier for me to edit and keep track of things.

1 Like

Sorry but i didn’t understand. Could you explain it a bit more? I got a question like:

What kind of Module?

I need to keep the client stuff client sided, so i can prevent the lag in the game (Like creating a frame for each item). Thanks for reading.

You do not need to have everything in the same module. This will be your shop / storefront handler module, used for interactions with store items on both client and server side. You probably want to make another module to handle shop GUI interaction for the client only, and make it require the other one.