I’m trying to decide how to do the UI system for a game I’m working on. The first question I’m running into is just whether to do it on the client or the server. I know what you’re thinking. “OMG of course you do UI on the client!” But is that really the only way?
Consider this scenario: You want a block that when you touch that block, a shop opens. Now, when I go over to the block in Explorer, I can either add a LocalScript or a Script. If I add a LocalScript though, it doesn’t run. If I add a Server Script, it does. So to do this on the server, all I need to do is add a Server Script, connect a Touched event, and in the Touched event, Clone the part and parent it to the PlayerGui of whoever touched the part.
Also consider that I might want arbitrarily many shops throughout the game that each sell different things or have different interactions associated with them. It seems cleaner and simpler if the server just looks at where you are in the world and clones the right shop into your PlayerGui.
Doing this on the client seems clunky. The server script still has the Touched event on the part, but now it fires a RemoteEvent to the client to open the shop, then the shop fires a RemoteEvent back when it makes an interaction, server then validates and responds with whether the transaction succeeded. Minimum of 3 RemoteEvents per shop.
Another idea would be for me to even do the Touched event on the client, so basically UI is 100% on the client, except for making a purchase, which is validated on the server. Now I’m down to 2 RemoteEvents per shop (or maybe 1 RemoteFunction), but getting code to run on the client is annoyingly difficult and high maintenance since LocalScripts don’t automatically run like server scripts do.
I could have one giant InitializeShopTriggers() script under StarterPlayerScripts that just goes through my Workspace world and connects Touched events to everything, but maybe all shop locations are not even cloned into the Workspace on startup, so I’m looking for advice on how to effectively manage all of this.
Hopefully this all makes sense.