Best Practices for Modular Helper Functions

My programming experience in PHP and C++ far surpass those of Lua; therefore, there are some things I am not familiar with in Roblox Lua.

Objective: Create a helper function, in_array(obj, array) to use throughout various scripts of my games.

Which would be the best approach for performance and availability?

  • Global Function
  • Required Module Function
  • Remote Function

I would do module, easy to move to new game and can be required easy enough for all in game applications.

The module runs and caches so all subsequent calls are just references to the returned value so it is very lightweight for the availability it has across the game.

Roblox doesn’t like globals, you want as few remotes as possible(within reason)

1 Like

Would I need to put the module script in ReplicatedStorage so LocalScripts could use it?

Yes, or replicated first if you need it really early or workspace is replicated too, but there’s not a good reason to put it those places.