Should I be using global variables or a bindable function that retrieves the variable?

For context, I have a daily rotating shop system that works perfectly. The next part of this system is adding a way for players to purchase from the shop.

I have two scripts, one for the rotating of the shop and the other that handles purchases. I want to make sure the player isn’t trying to purchase items that aren’t in the shop (cause of exploiters) and the way I can do this is by either setting up a global variable of all shop items or I set up a system where whenever a player tries to buy something, the purchase script invokes a bindable event to check if the item they want to purchase is in the shop.

I’m leaning towards using global variables, but I’m not sure. Any help is appreciated :slight_smile:

(My main concerns are security regarding global variables and possibly flooding network usage by using bindable functions.)

Keeping it behind an interface like with BindableEvents is generally a better idea. Some things are just more convenient to have as globals because it’s relevant to every script or most scripts, but I wouldn’t do it with what you described. If you get bugs because some script somewhere is changing the global variable when it shouldn’t, or doing it in the wrong way, that can be really hard to debug. Using a BindableEvent, you can control exactly how and when it can be set.

2 Likes