Is having a lot of functions worse than directly writing the code inside the function?

I’m trying to optimize my script a little bit, and a question came up. I decided to use a lot of functions to make the code easier to read and look cleaner. So, for example, I’d do…

local function DeleteOldInstances()
	if Player:FindFirstChild("Quest") then
		Player.Quest:Destroy();
	end;
	if Player:FindFirstChild("NoExp") then
		Player.NoExp:Destroy();
	end;
end;

-- then, maaany lines later
DeleteOldFolders();

…instead of directly writing down the block of code

if Player:FindFirstChild("Quest") then
	Player.Quest:Destroy();
end;
if Player:FindFirstChild("NoExp") then
	Player.NoExp:Destroy();
end;

I do this mainly so I can collapse the functions and shorten the lines so I can work better on other, more important code.
I’m guessing it’s the same thing but I always prefer asking stuff I am not sure about.

if you need to call the function more then once, then do this one to prevent repeated code

1 Like

I only call it once, but as I said…

So is using functions worse than direct lines of code or not?

in terms of performance then functions would be worse(it isn’t that much of a difference)
in terms of readability then functions would be better(because as you said you can collapse the code and you can prevent repeated code)

Oh alright, thanks! I was wondering what would’ve changed between the two methods.

1 Like