FANDOM


In Lua, a Method, or Function is a block of code that can be executed multiple times. Methods can belong to instances, tables, or global. Functions can be defined using the 'function' keyword.

The following code would create a function and run it.

local function MyFunction()
    print("Hello world!")
end
 
MyFunction()

The following would also create a function and call it once.

local MyFunction = function()
    print("Hello world!")
end
 
MyFunction()

Additionally, methods can belong to instances. For example...

local part = Instance.new("Part")
print(part:IsA("BasePart")) -- IsA is a method of the created part.
Community content is available under CC-BY-SA unless otherwise noted.