Simple Roblox Lua Function

Here is a simple Roblox Lua function with explanations for each step:

-- Function to double a number
function doubleNumber(number)
    -- Multiply the number by 2
    local result = number * 2

    -- Return the doubled number
    return result

-- Call the function with an example number
local exampleNumber = 5
local doubledNumber = doubleNumber(exampleNumber)

-- Print the result
print("The doubled number is: " .. doubledNumber)


  1. The code starts by defining a function named doubleNumber, which takes in a parameter number.
  2. Inside the function, the number parameter is multiplied by 2 and stored in a local variable named result.
  3. The function then returns the value of result.
  4. After the function definition, the code continues with the main program logic.
  5. A variable named exampleNumber is declared and assigned the value of 5.
  6. The doubleNumber function is called with exampleNumber as an argument, and the returned value is stored in a variable named doubledNumber.
  7. Finally, the program prints the result by concatenating the string "The doubled number is: " with the value of doubledNumber.