Module 6 · Functions and scope
Callbacks and the colon syntax preview
Pass a function to run later and read object:Method() as a method call.
What you will learn
- Recognize a callback function value
- Read colon method-call syntax without introducing metatables
- callback
- A function supplied for another API to call at an appropriate time.
- method
- A function associated with an object and called with colon syntax.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
Roblox events run callback functions later, and services expose methods such as GetService through colon syntax.
The mental model
A callback is passed without calling it immediately. The receiving API decides when to call it.
In object:Method(), the colon associates the call with object. The deeper implementation details can wait.
New words and symbols
--!strict asks Studio to check your code for type mistakes. It is an instruction for the editor and produces no Output message.
Matching quotes such as "hello" surround a string: a piece of text. The quotation marks tell Luau where the text starts and ends.
print(...) calls the built-in print function. Put the values to show inside its parentheses; separate multiple values with commas. Read the result in Studio's Output panel.
local is read as “local”: it creates a name that is available only in the current code scope.
end is read as “end”: it closes a block such as a decision, loop, or function.
. is read as “dot”: it accesses a named property or table field.
A tiny example
--!strictlocal function announce() print("Delayed Coin Quest message")endtask.delay(1, announce)print("Scheduled")Line by line
- 3
announce is defined as a function value.
- 7
task.delay is called with colon-free library syntax and receives announce without parentheses.
- 8
This message can print before the scheduled callback.
Read the code aloud
Read one statement at a time: name the value being read, what the operation does, and where its result goes. Keep identifiers exactly as written so you can find them again in the code.
Pause at calls, conditions, and loops. Explain when the body runs before moving to the next statement; use the line notes above when a symbol is unfamiliar.
Execution trace
Start with the statements outside function bodies. A function definition creates a callable value; its body runs when a call, event, or scheduled task reaches it.
Trace the arguments at each call and the branch or loop inside that call. Return to the caller when the function returns. For an event, use the action named in Try it to trigger the callback.
Line 3: announce is defined as a function value.
Line 7: task.delay is called with colon-free library syntax and receives announce without parentheses.
Line 8: This message can print before the scheduled callback.
State before and after
Before running, identify the starting values and any existing Studio objects this example needs. List what you expect to change.
After your practice change, check this result: You can distinguish passing announce from calling announce() immediately.
Reading or printing a value leaves it unchanged. Look for assignments, calls that change state, and property updates to explain each change you observe.
Predict before running
Which message is scheduled for later?
Try it
Mark each step after you have tried it.
Common mistake
task.delay(1, announce())Parentheses call announce immediately and pass its return value. Pass announce when the API expects a callback.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Callbacks are function values passed for later use.
- Calling and passing a function are different actions.
- Colon syntax calls an object's method.
Next: Next, you will build and test a typed pure damage function.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.