This may not be exactly Scripting, more of a Studio Organization thing, but since this involves scripts, I’ll put this here,
How would i minimize the Amount of scripts i use?
Usually i would have multiple scripts handle certain things, but the issue is that this can cause slight performance issues in Studio, and in the game itself.
Is there a way to minimize how many scripts i use, or will this have the same effect of downgrading performance?
This isn’t really true. If you’re getting bad performance with multiple scripts, you’re probably going to get bad performance if all of them are in module scripts with one being required or whatever.
Write scripts in a way that they are easy for you to read and write and find later. I write lots of separate scripts and a whole lot more libraries with modules and such.
But im nore of just asking about how would i minimize the amount i use to prevent a form of performance drop, Usually when you have multiple, it can cause a slight downgrade in performance (memory, or network?), and maybe small amount of frames will drop.
I get that, the only issue is that its tedious to look for that specific script, even with folders to organize (that may just be me) , I’d rather have my scripts cover certain functions like One does RemoteEvents, one does Calculations like formatting numbers and such rather then just multiple for a specific.
So im more of asking how would i organize scripts better,
I get that this is a pretty basic answer, and probably not going to be the solution, but have you thought about combining scripts? Instead of having let’s say 5 scripts to handle small things combine them into one.
You could probably limit it down to only a few scripts, or more if you like to use ModuleScripts. You can basically just make a Main and LocalMain.
This will help in some ways because the roblox engine won’t be trying to read let’s say 20 scripts, but rather just 1 script that is extended and only triggering at some times. I would assume that it uses more memory and impacts more to have the roblox engine try to open 10 scripts than 1-3 of them.
I have,
I try combining certain scripts for certain functions, like events, the thing I’m more concerned about is that since I’m putting the equivalent of one script into another, will it downgrade performance?
This is how it was done in a group that I currently work at, we have about 100 scripts (5 being real scripts, the other 95 being module) and the modules usually have about 100 lines of code whereas the main files have 2000+ lines. Now it’s difficult to say, because I never did compare it, but I never end up with lag in the game, so I assume it works.
I can probably see how much memory it uses though.
Now, while not fully reliable I opened a new game and added 5 server scripts. Each doing the same thing. Adding 1 part after 10 seconds of a player joining.
When you have 5 scripts doing it, the PlaceScriptMemory jumps by about 1.2 - 1.5 MBs (not many) and when you do all 5 in one script it only jumped by about .3 - .5 MBs (still not many)
I would say that either method should work just fine unless you are planning to be using a lot of scripts. Since without too many, you won’t have that much of a memory impact.
First thing I would do is enable View->Performance in Studio.
Then look at your
PerformanceStats->Memory->PlaceScriptMemory
as well as
PerformanceStats->Workspace->FPS.
Make sure you are getting a performance hits from Scripts and not from something else. If your scrips seem to be using to many resources then begin disabling ones that you assume are the biggest offenders and see what the impact is. You might need to just clean them up and write the code differently.
Also, If you have scripts adding functionality to specific areas in the game that players won’t notice for a while disable them until certain conditions are met. As an example. If you have an area with 5 scripts adding functionality have an event that only enables these when the player is close enough to experience them. Then turn them off when players are no longer around.
Unless you have a bunch of scripts that trigger from people being inside the game I think using Studio should be fine. When I run my experience in Studio I can move my mouse to the Performance Navigation Pane and open the drop down boxes to see what’s happening live. Not sure what kind of game we are discussing so I’m not sure If your mouse is locked from doing that in any way.
This still shouldn’t be true. The networking difference is going to be both extremely minimal (because server scripts don’t send their sources to clients) and cold (since it’s only going to happen in the initial snapshot). After whatever compression steps we’re doing right now the cost should be effectively free. I expect that you lose far more from a single part than you do on a script.
Frames shouldn’t be impacted at all, work is work whether it’s in another script or not.
Don’t worry about performance until it actually becomes an issue, and don’t optimize without finding out first definitively what the issue is. Write the code you want to write, and don’t worry about this if your only concern is performance