Way to fetch variables from scripts?

i have a script that handles inventory system, and another script that handles crafting, i need to fetch inventory table from the first script and get it into the crafting system script, how would i do that?

should i make a module script or that would be exploitable?

should i make the inventory a global variable or it wouldn’t work??

do you guys have any other ideas if none of these work?

Hey, ModuleScripts are not exploitable if you use them only on the server side.

RemoteEvents/RemoteFunctions

If your crafting system runs on the client but needs to fetch server-side inventory data, you can use RemoteEvents or RemoteFunctions for communication between the client and the server.

Global Variables (Not Recommended)

  • Hard to debug: Any script can modify _G variables, leading to unpredictable behavior.
  • Security risks: If a client somehow gains access to _G, they can exploit it.

BindableEvents/BindableFunctions

  • If both scripts run on the server, you can use BindableEvents or BindableFunctions to share data.

can client fetch the module script without exploiting it?

Both the crafting system and inventory system should be on the server, and _G is not type safe nor is it optimized. If both systems have to be separate, the RemoteEvents should suffice.

Editing replicated module scripts on the client does NOT replicate the changes to the server.

yea i know, both crafting and inventory system are on server, i just need a way to fetch inventory table from inventory system script to crafting system script, i just cant think of a way

Unless the script’s parent is replicated ex (Workspace, ReplicatedStorage, ReplicatedFirst, StarterPlayer, Player, etc. are; ServerStorage, ServerScriptStorage etc. aren’t) So put the module in ServerStorage and the client will never get access to it.

1 Like

If you are concerned with code safety, checkout #help-and-feedback:code-review I’m sure people there will address your concerns.

The ModuleScript acts as a shared source where both your inventory system and crafting system can access and modify the inventory table.

so if im understanding you right, if i put my module script in workspace, replicatedstorage, etc, client is able to access and change it but it wont change on the server side, but if i put it in serverstorage, client wont be able to see it at all, am i right?

ServerStorage

  • Items placed in ServerStorage are only accessible by the server.

ReplicatedStorage

  • items in ReplicatedStorage are accessible by both the server and the client.

but if client changed the module script thats parented to replicated storage, would it change in server-side as well?

I answered this in a previous reply, no it does not.