What is syntax local function do

trying to create a new reset button

local func do

end

local coreCall do 
	local MAX_RETRIES = 8

	local StarterGui = game:GetService('StarterGui')
	local RunService = game:GetService('RunService')

	function coreCall(method, ...)
		local result = {}
		for retries = 1, MAX_RETRIES do
			result = {pcall(StarterGui[method], StarterGui, ...)}
			if result[1] then
				break
			end
			RunService.Stepped:Wait()
		end
		return unpack(result)
	end
end

assert(coreCall('SetCore', 'ResetButtonCallback', false))

also how do the parameters even get past through?

is set core the method?

what are the … in the parameters?

1 Like

It’s two separate things.

local func

Just makes a new variable without setting it to anything.

do
  -- ...
end

Makes a new Scope | Roblox Creator Documentation.

In the example you showed, they are “hiding” the MAX_RETRIES, StarterGui, and RunService variables from the rest of the script by sticking them in a narrower scope.

function coreCall overwrites the local coreCall method that they created outside the scope before—that way, later in the script, you can use the coreCall variable as a function, but accessing MAX_RETRIES would fail.

Here’s a simple example:

local someVisibleFunctionName -- make a variable but don't assign it

print(someVisibleFunctionName) --> nil (because it's not defined yet)

do -- make a new scope

  local someHiddenVariable = "you can't see this outside of this do ... end"
  
  -- define the variable
  -- could also say
  --   someVisibleFunctionName = function(arg) ... end
  -- instead
  function someVisibleFunctionName(arg)
    print("woo", arg)
  end
end

print(someVisibleFunctionName)  --> function: 0x13de750
someVisibleFunctionName("asdf") --> woo asdf
print(someHiddenVariable)       --> nil
4 Likes