Luau (programming language)
Luau is a Programming Language based on Lua and developed by Roblox Corporation and used in Roblox Studio to create games on Roblox.
![]() | |
Family | Lua (Programming Language) |
---|---|
Developer | Roblox Corporation |
First appeared | 27th August, 2019 |
Preview release | Unknown, Roblox Staffs only
|
Implementation language | C++, Lua |
Platform | Roblox, Roblox Studio |
OS | Windows, MacOS |
License | MIT Licence |
File formats | .txt, .rbxm |
Website | official website: https://luau-lang.org
Roblox Wiki: https://roblox.fandom.com/wiki/Luau Repository: https://github.com/luau-lang/luau |
Examples
Instances refers to objects in the game and some of them can be parented and some have a "child".
Part spawns in constant code
Here's an example code for spawning a "Part" (Roblox Block instance, shown here as "brick") every 10 second. Spawning in the position 0, 0, 0. "game" refers to the game itself. "Workspace" is where the player can interact, a 3D environment. "CFrame" is used as the position of "brick".
while wait(10) do
local brick = instance.new("Part")
brick.parent = game.Workspace
brick.position = CFrame.new(0, 0, 0)
end
Note that "Workspace" is a child of "game". This script is a "Script" instance and it's placed in "ServerScriptService", a parent of "game".
Function codes
Another example is to use custom functions and instance's "Signal". If the instance has triggered a change, the signal will be fired. In this example, instance "Button" has a "ClickDetector" which fires the signal "MouseClick" whenever "Button" is pressed. "Connect(<Name Of The Function To Run>) is to run the function in the parenthesis whenever the Signal is fired. This time we are going to run a custom function called "onClicked()" and it will change "Button's" colour and material.
Button = script.parent
function onClicked()
button.BrickColor = BrickColor.new("Medium Stone Grey")
button.Material = Enum.Material.DiamondPlate
end
Button.ClickDetector.MouseClick:Connect(onClicked)
Adding comments
See the code block below to see the example of comments.
--See here for the use of comments
--This is an example comment
--[[This is an example of Multi-line comment
hello world,
This is a Wikipedia edit.]]