Coding optimisation questions I have

I have a few questions in regard to coding optimisations.

Is it okay to have multiple of the same connection in different scripts?
For example having multiple player added connections in multiple scripts. Is that bad? Because I usually do everything in one playeradded connection and it gets complex.

Does having more scripts and module scripts affect optimisation?
Like spamming module scripts for functions.

Is having a lot of variables bad? Yeah I get that it creates places in memory but I dont get the difference.

Why do we use local variables instead of global variables in luau?

yes, it’s okay

having many modules or scripts will not affect performance what will affect performance more is the code logic

they will not consume much memory but using unnecessary variables may make the code unreadable

because luau access local variables faster than global ones and because of scoping

Scope | Documentation - Roblox Creator Hub

Okay but isn’t that just making extra connections in memory?

yes, but that isn’t a lot of memory to worry about
if you don’t want to create my connections you can make multiple functions and use them in 1 connection

i have created about 1000 connections and it only consumed about 8 megabytes

local Players = game:GetService("Players")

for i=0, 1000 do
	Players.PlayerAdded:Connect(function()
		for i=0, 100 do
			print("EEE")
		end
	end)
end

and a million connection consumed about 200 megabytes

local Players = game:GetService("Players")

for i=0, 1e6 do
	Players.PlayerAdded:Connect(function()
		for i=0, 100 do
			i = i + 5
		end
	end)
end

Although it doesnt make that much of a difference, it’s still better to put all of your playeradded logic into one connection because it’s easier to manage.

1 Like

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