Best practice in Server/Shared/Client scripting?

This is the first language where I’ve had to work with client & server sided operations. I’m still trying to figure out how I should script for the client, server, and shared properly. Yesterday I finished up a custom chatbox but didn’t touch anything in the shared files. Basically on the client’s side I’m displaying vgui elements, when a player types a message it networks the player’s entity & message to the server. The server scans for other nearby players and networks back to all those clients basically saying “you have a new message”, the client side receives the network message, stores the new chat message in a table, and updates the vgui elements accordingly.

Could anybody point out some examples where I might need to use shared, and maybe some incorrect usage of shared, server, & client scripting? Or maybe a tutorial somewhere explaining this in more detail?

The rule of thumb is if both the client and server need access to it ( with potentially small changes to each ) use SHARED. If the client needs it and not the server ( such as vgui stuff ) then use CLIENT. If the server needs it and not the client ( such as server-side only details, confirming data, etc ) then use SERVER.

Hey, welcome to FacePunch.
I have written over 400 tutorials and completed “systems” in Lua for Garry’s Mod. I tutor and answer questions for free; feel free to add me on Steam if you need some guidance. This forum is for devs that need help working on things. Here are some resources to help you get started:

Generalized Lua Help ( Links to Wikis, Answers the question of “Where do I post a simple question or DarkRP Specific question”, links to other resources compiled by forum members )

Useful Programs ( SteamCMD, Autosizer, Desktops, Process Explorer ) and Notepad++ Upgrades

Acecool Dev Base Skeletonized Base Game-Mode ( Never worry about Include or AddCSLuaFile ever again; comes with New Hooks, Console Commands, Meta-Table Objects, Helper Functions, Extended Functionality, and more! )

acecooldev_base Addon - All of the features above, but packaged as an addon. [ COMING SOON ]

I may be able to help you further, add me on Steam. Here are some tuts / forum posts I have related to realms, hopefully they help.

Including files across realms:

Just because something is shared doesn’t mean that it executes on both the client and server when it is called from either server or client. The client has its own execution line, as does the server.

Explanation of realms:

Hey, thanks for the reply. I began using your base gamemode the other day as well, which is also helping to clear things up a bit as far as realms and networking goes.

I tried adding you on Steam but it’s giving me an “Error adding friend. Please try again.” I’m not sure if its just Steam acting up or maybe some privacy settings?

I added you; removed a few that I don’t think ever sent me a message.