1 file VS split files

I wanted to know which would be better for an addon

1 file which has code for both Client and Server and is located in /autorun

2 files, 1 has Client side, 2 has Server side and each sit in corresponding autorun/server and autorun/client

And a different question is, when do you actually use AddCSLuaFile?

I have made scripts before and never really needed them as they were already suppousedly being sent to client, and i could use them propertly.

It is a matter of preference really. Sensible thing to do is, if there are a lot of code - split it. If you use a lot of shared functions, use one file with SERVER and CLIENT checks.

You must use AddCSLuaFile for every clientside and shared Lua script, especially if you plan using them in multiplayer or releasing the addon. AddCSLuaFile must be called from server, it doesn’t do anything on client.

But why is it a MUST if it works without? I’ll still add it, but weird that it still works all fine without it.

Because while it works for you, since you have the files on your computer, it will not work for anyone else that will try to join your game, or a server with your addon installed.

Weirdly for you to say that, because all the stuff i made before (without AddCDLuaFile), has worked for anyone else that joined.

For example? The only stuff that will work is serverside stuff. If you don’t AddCSLuaFile HUD or panels, they will never appear on other player screens.

no, i have mystuff on server addons/newjorciks/lua/autorun/script.lua

It has both SERVEr side scripts and CLIENT side scripts

Serverside has stuff like database access (btw ik should not have sensitive data like that in shared)

Clientside has vgui and some other stuff

Everything works with no problems without AddCSLuaFile, weird after you say it shouldn’t even work

I was thinking it maby automatically adds them if they are there, idk rly XD

Scripts in /lua/autorun/ and lua/autorun/client are automatically added to the download list from what I’ve tested.

I wouldn’t suggest putting them there, though, just for organization’s sake in the filesystem, put one file in autorun that handles AddCSLuaFile and includes. Everything else in it’s own folder. Not meshing around with other files.