Optimization Tips for 300+ Player Sessions

Could you tell us more about what features the game has and how much experience you have with scripting?

General

I’m an optimization freak and recently finished two game optimization commissions, so I hope my words hold some weight.

But just some general advice, if you go to the Learn section in the Creator Hub, Roblox has some great videos on optimization and good practices for less memory.

Here we go…

Optimizing a game stems from the system’s architecture. Ensuring clean communication between scripts by having a modular system, using frameworks (i.e., Knit/module loaders, your own framework) will reduce tangled/spaghetti code.

Also I like to use libaries like Signal for easier cross-script communication, Packet as a RemoteEvent replacement, Maid to handle connections in the same scope/entire script, and certainly use a data library like ProfileStore for your Datastores. And the reason why I recommend these is that they really just make your work so much easier.

You’ll learn to optimize scripts and systems overtime (if you choose to, and you probably should). A lot of free models/kits/whole systems made by other people could have deprecated functions and outdated code. If your game has these, you should replace or look into these scripts and look for optimization opportunities there too. Also checking the output will show dead giveaways of broken/dated functionality.

Understanding and implementing concepts like OOP/ECS, modular programming, client-server replication are also game-changing. Refactoring some parts of the game to implement these will help with ease of use, future scalability, and performance.

The final caveat is that sometimes it’d just be best to rewrite parts, if not the whole game, but that may not be feasible if the game is too big already and you don’t call the shots.

Specific Tips

  • If your game has a lot of instances being created (i.e., bullets, sounds, and anything else temporary), consider looking into object pooling.
  • Use dictionaries instead of large elseifs. A rule I have is to not use elseifs at all.
  • Turn commonly typed things into variables as much as possible. For instance:
if player.leaderstats.XP >= 10 then
end

if player.leaderstats.XP >= 20 then
end

could be turned to

local xpValue = player.leaderstats.XP.Value
if xpValue >= 10 then
end

if xpValue >= 20 then
end
  • Also apply the same concept to copy-pasted blocks of code and turn them into reusable functions.
  • Use the Find in Place tool (ctrl + shift + S) to search for variables, etc, within all of the game’s scripts and see which scripts use certain module functions/variables, etc. This also makes it easier to debug large systems. It’s basically the script Find tool (ctrl + F) but searches every script in the game.
  • Compare snapshots in the DevConsole to find scripts that degrade performance (source)
  • Somtimes, you’ll see the same TweenInfo in every TweenService:Create() line, so just turn that into a variable and reuse it. I like to just define all my TweenInfos as variables for this purpose.
  • Understand when to use WaitForChild and spot signs of redundant uses in the game (source).
  • When creating a new instance, parent it last separately from the Instance.new() function. (source 4:05-6:54).
  • Never do while wait(x) do (source)

This is just all I can write off the top of my head right now, but yeah. Hope this helps!

2 Likes