Hello everyone, I have a few dictionaries, that contain the cost in wood, stone, and gold of each craftable. However, I have three scripts that need this information, and so far, I have just been copy pasting each change to each dictionary. Is there a way to store these dictionaries so multiple scripts, local and server, can see them? Thanks!
Is there a way to store a global dictionary so that multiple scripts (local and server) can see it?
You could use a ModuleScript that has functions for returning dictionaries.
Alr, thanks! I will test it right now.
You can try using _G. I haven’t tested it myself, but I’ve seen it in use as a global dictionary.
Literally the very function of module scripts…
I am fairly confident in my reply, but anyone please feel free to let me know otherwise, I wrote this at 2 AM lol
Like a few others have said in this post thus far, ModuleScripts are your best bet at having a “global” dictionary.
What I haven’t seen at the time of writing this post however, is that you cannot access server sided values of said dictionary on the client, assuming that was what you were going for.
You’re going to want to setup a remote event that fires the server sided dictionary to the client or all clients at the start, and then have that event fire every time the dictionary changes. How this is setup is up to you, I am sure there’s an easier method, but at the time of writing this was the best solution I could come up with.
You can access ModuleScripts in the client though? Did I misunderstand you?
While this is a valid method, it’s generally bad practice because
_G. is super slow and unsafe if compared to more reliable methods like ModuleScripts : )
You can yes, but OP was also asking if the client and server can access the exact same dictionary. I assumed he meant if the client and server can access the same exact dictionary and values, hence my reply. If you’re on studio right now, feel free to do a test and reply to me again, I might be wrong, but to my knowledge you cannot access the same values.
Ex: Say I made a table named Bob and I added a value to it named Builder.
If I decided to add another value to that table serverside at runtime named Builder2, unless you fire a remote event to the client to update the table client side, if you try to access Builder2 on the client it will return as nil.