What is the best way to set up a script?

Hello. I am having trouble deciding how I want to set up my script. I was wondering if it even mattered in the first place. Would It be better to set up my script like so:

method 1:

--localScript
local function run()
  wait(1)

  local function help()
       ---Do stuff.
  end

   --Do stuff.
   help()
end

while true do
  wait(4)
   run()
end

or should I set it up like so:

method 2:

--localScript

local function help()
       ---Do stuff.
  end

local function run()
  wait(1)

   --Do stuff.
   help()
end

while true do
  wait(4)
   run()
end


I am usure if method 1 uses up more data than method 2 or vise versa. Can somebody possibly help explain to me which method might be more efficient to use long term?

Probably use HeartBeat function instead of while loop. However, avoid usage of wait and instead use task.wait().

I would say that you will use method 2, so it is easier to read and in memory loss I think it is less because it does not create and remove the variable over and over again, it keeps it, since it will always use it.

you should also use task.wait but it is not related to your question

1 Like

Method 2, it will be easier for you to script.

The second method is good, but the cleanest framework is by writing your functions in a module script and then creating a local script that requires that module script.