What are some lines of code that will impact game's performance?

Scripts may lag the game depending on the code used on them.
Some of the stuff I know that impact game’s performance(Not lag in some cases) are :

RunService.HeartBeat
TweenService
Instance.new()
Destroy()
while true do wait() end
coroutine
wait()
FindFirstChild("X", true)
RunService.RenderStepped
Clone()
repeat wait() until x

(If I’m wrong on the examples above, correct me.)

Do you know any other type of code that can impact game’s performance?

1 Like

wait(), Instance.new(), TweenService dont impact the performance, as per my experience.

_G variables

they have a significant impact on the game’s performance, when you can just use BindableEvents or other ways to tranfer data.

Debris:AddItem()

tried it, next thing you know my game as averaging 30-40 FPS whenever it was called.

1 Like

Any code that is run multiple times aka any loops can cause problems if used wrongly.
You can see that what scripts are problematic in studio under Script performance tab or in live games in the mirco profiler.

3 Likes

80% of these will not impact performance that much if you do it correctly, don’t leave loop running when they are not used this will cause memory leak. There is nothing wrong with RenderStepped and Heartbeat. I haven’t heard :Clone() and :Destroy() causing performance to go down. TweenService can cause lag when using it too much on the server and can cause the Tween to slow down. With Instance.new if you use the second parameter it will impact performance as shown here. Please correct me if I’m wrong.

2 Likes