io.read, we mean "the
readentry from the
iopackage". For Lua, that means "index the table
iousing the string
"read"as the key".
xstarts at 0, increments by 1 in each iteration of the
forloop, and is printed again afterward with a final value of 5.
xis set to 0, and another local variable
xis declared inside the
forloop. As the loop iterates, its locally-scoped
xis printed with a constant value of 1, then the initial variable
xis printed with an unchanged value of 0.
functionkeyword followed by the function name and a pair of parentheses (
()). Since the function’s body will be a block of code, it must be closed with the
endis where commands and other code make up the function body. These commands will be executed when the function is called:
returnvalues. Working off the example above, the following function returns the sum instead of printing it:
delay()call or a
ModuleScriptswhere the module’s table contains various functions:
Wait()function will cause the script to pause until the event occurs once. When it does, the function returns the data associated with the event’s firing.
Connect()function can be used when a given function should run every time an event fires. This function immediately returns a connection object. In the example below, we connect a function,
onTouched(), to a
Workspace. If another part collides with
myPart, the script prints the name of the other part involved in the collision.
Disconnect()method of the connection object returned by
RemoteEventcan be used. This works similarly to
BindableEventbut is network-ready.