Module 10 · Client and server
RemoteFunctions and when not to use them
Use request-response only when a caller truly needs an immediate returned value.
What you will learn
- Explain RemoteFunction request-response
- Recognize yielding and avoid unnecessary use
- RemoteFunction
- A Roblox object for a network request that waits for a returned response.
- yielding call
- A call that pauses its thread until it resumes or returns.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
Coin Quest may need an initial server-owned shop snapshot, but fire-and-forget actions do not need to block a client waiting for a response.
The mental model
InvokeServer yields the client until OnServerInvoke returns or fails. That can be appropriate for a small requested snapshot.
Use a RemoteEvent when no immediate reply is required. Never invoke clients from the server for authoritative decisions.
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.
if is read as “if”: it starts a decision by evaluating a condition.
then is read as “then”: it marks the body that can run when the condition is truthy.
end is read as “end”: it closes a block such as a decision, loop, or function.
return is read as “return”: it ends the current function call and sends a value to its caller.
: is read as “colon”: it calls a method with the object supplied as the first receiver value.
A tiny example
--!strictlocal ReplicatedStorage = game:GetService("ReplicatedStorage")local getShopSnapshot = ReplicatedStorage.Remotes.GetShopSnapshotassert(getShopSnapshot:IsA("RemoteFunction"), "Expected RemoteFunction")local ok, snapshot = pcall(function() return getShopSnapshot:InvokeServer()end)if not ok then warn("Shop data is temporarily unavailable")endprint(snapshot)Line by line
- 3
The remote is read from a fixed shared path.
- 5
The class is checked.
- 7
pcall contains a network failure.
- 8
InvokeServer yields for the server response.
- 11
Failure produces a plain recovery message.
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: The remote is read from a fixed shared path.
Line 5: The class is checked.
Line 7: pcall contains a network failure.
Line 8: InvokeServer yields for the server response.
Line 11: Failure produces a plain recovery message.
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: Each RemoteFunction use has a necessary immediate result and a failure path.
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 action does not need a RemoteFunction reply?
Try it
Mark each step after you have tried it.
Common mistake
Do not make the server call a client RemoteFunction to decide currency or purchases. A slow or malicious client could block or misreport the authoritative decision.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- RemoteFunctions provide request-response.
- The invoking thread yields.
- Prefer events when a reply is unnecessary.
Next: Next, you will assemble server validation and local feedback into secure coin collection.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.