How to make a high performance game?

There are multiple ways, for example:
-Disable “CanCollide”,“CanQuery”, “CanTouch” and CastShadow to parts that dont need any of these. Disabling those should help you reduce lags and make the performance better.
-Dont use too many While Loops, try to use Events if possible or run things through client with RunService
-Try to have as few parts with transparency as possuible as parts with transparency/Reflection tend to be heavier.
-Disable Shadows in SpotLights/PointLights etc.
-Dont have 100 scripts in 100 parts, instead you could either have a module or CollectionService.

-Always make your scripts clean and dont use useless/too repetetive stuff when no need.

There are some other ways you could use to make the performance better; both in terms of building and scripting.

Also, make sure youre using RemoteEvents/Functions correctly with sanity checks and debounces to prevent people from spamming the remote.

12 Likes

Also, client tends to run faster than server.
Fun fact: a player’s character is fully client sided! The character is the only safe place for a local script to run as a descendant of workspace. Server scripts do not run in the character because of this unless workspace.RejectCharacterDeletions is Enabled.

9 Likes

Keep in mind, the more loops running, the less smooth your game will be.
This is because the Task Scheduler will have a lot more things to do.

9 Likes

A lot of this involves the way you organize you game and code, but it is possible to do and not a very tedious process if you fully understand what you’re doing, and what changes you are making.

One thing people recommend doing to make for performant games is to have specific functions run on seperate context levels (i.e Server or Client), The Client is essentially the Players view of the game, while the actual game is taken care of by the Server, The Client should take clear of visuals like Particles, Graphical Interface, Tweenings, and Animations, while the Server should handle all the Important Calculations thats are nessecary for running your game like a Round System, Times, Currency, or DataStores.
If the Server is managing these items, it can slow down your game, as the Server is calulating and applying changes to something it shouldn’t which is using more resources, the Client will be a lot smoother, and faster to apply these changes, because they are not too important, you can tell the Client to make these calulations, and changes.
If you are trying to Send Data between Clients and the Server, or just trying to replicate an effect to all Players, you use RemoteEvents.

If it comes to Sending Data using RemoteEvents (allows you to send Data to the Client or Server), make sure you perform sanity checks to avoid any exploits from the Client, About every single Exploit will be executed from the Client, and RemoteEvents can allow Exploiters Access to the Server, so when performing specific tasks, always assume that the Client is false, and make sure the Data is correct.
For Example, .Touched Events that are handled by the Client can be manipulated as any changes that are applied to Client objects will also apply for the Event on the Client, in essense exploiters can change the location of the object, and the event will adjust according to Client Changes, a simple fix to this problem would be to ensure that the Player is in the Correct Spot using the Server, Client Changes will not apply to the Server unless explicity told to, so any change to the part on the Client wont happen to the Server, making it an ideal place to do it.

The Optimization here that the client is in charge of the event, and what fires while the Server is in charge of what goes on in the Event, the Server is not in charge of detecting whether or not the Player has Touched the Part, but whether the RemoteEvent has fired, where it can then check to ensure that the Client’s Response is true, in many cases, this can also be used as an anti-exploit.

As for your Example, that can be done with CollectionService. which allows you to Tag Objects, and to Apply Stuff with the Specific Tag, instead of having multiple threads run at a time to apply a single connection, you can instead use the Service, and one script to apply these for you, which is more efficient, and keeps your game more organized.
This isnt really the only Example of its usage, it can also be used for a variety of other things, it can also be used for Players who are maybe on a Specific Team, or Weapons that require a specific tuning to work properly, it is up to you how you want to use it

ModuleScripts are intended help you Organize your Code, and if used correctly, can make for very neat, and awesome things, something often people do is create a “Library” of sorts to store Modules which allows them to easily find what they need, or for a Module to get what it needs.
They themselves dont really provide any Optimizations, they just allow you to store code and data in them, which can then be fired from a Script, However they can be useful for Optimization purposes.

Another thing you also keep take note is that, not everything you do will make the game performant, There are specific optimizations that you may have to sacrifice in order to secure your game properly to have everything together, and inproper usages of code, or Services can slow down your game, so you should always account for these circumstances when trying to improve stuff in your games.

11 Likes

Thank you again @remcodesremcodes! You are helping me a lot :smiley:

7 Likes

Thank you @Valkyrop! I just realized I forgot to add a variable that see if the remoteEvent has been fired, instead I put it WHEN the remoteEvent was called… Thank you!!

5 Likes

What do you mean with sanity checks too?

5 Likes

He means to check whether the Data given is true, which is what a Sanity Check is.

5 Likes

How could a use while loops and runservice without breaking/lagging my game?

3 Likes

minimise the amount you use, only use them if you must
if you can make a while loop have a long cooldown e.g
while task.wait(3) do
then that’d be great

6 Likes

Wow that was big! Thank you for everything you told me, it will help me in future! One thing I didn’t understand is the exploiting thing while on the remote event… Althought, I need to go now! Thank you everyone, see you tomorrow!

4 Likes

Debris Service destroys an instance after a set amount of seconds. This can useful for things such as projectiles or rubble, and can make your coding more efficient. Not too sure on if it is faster than doing it yourself manually in terms of execution time, but I’m assuming it is since it’s a built in roblox function.

local debris = game:GetService("Debris")

local part = Instance.new("Part")
part.Parent = workspace -- spawn a part into workspace

debris:AddItem(part, 5) -- destroy it after 5 seconds

This service also takes care of error handling. Example being if the part gets destroyed before the debris service can destroy it, it wont cause an error.

5 Likes

Thank you @awesomecooldude87! I will make use of that!

2 Likes

For example,

--server side
remote.OnServerEvent:Connect(function(Player,Code)
  --check if the code argument provided is what you want [string/number/bool,etc]
   if typeof(Code) ~= "number" then return end -- or "string" or "boolean" 
end

You could also do some debounces when using remotes, as shown here:

5 Likes

Are you saying that parts that have the transparency lower than 1 are more heavy or they are more heavy when they are at one/more than 0?

2 Likes

I am making something to check, if it is a value it returns nil, else it go further. Is that like a debounce?

1 Like

They are heavier when 0 transparency.

1 Like

The more they’re complete transparent, the more heavier [as I’ve heard].

1 Like

fr? But when transparency 1 you can’t see anything

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.