Why use BindableFunction?
BindableFunction supports a local request/response pattern. Its OnInvoke callback returns a value to Invoke; it does not communicate from client to server.
Try it in Roblox Studio
Put this Script in ServerScriptService and inspect Studio Output. The callback is assigned before Invoke so the example has a responder.
Syntax
function functionObject.OnInvoke(value) return result end
functionObject:Invoke(value)Examples
BindableFunction
Compute a local double using a bindable callback.
local calculation = Instance.new("BindableFunction")
calculation.Name = "DoubleNumber"
calculation.Parent = script
calculation.OnInvoke = function(value)
assert(type(value) == "number")
return value * 2
end
print(calculation:Invoke(7))- OnInvoke supplies the function that handles a request.
- Invoke(7) calls that handler and receives 14 as its return value.
- A handler that yields or errors affects the caller, so avoid unbounded work and handle failures in a larger system.
Best practices
- Assign a handler before invoking the BindableFunction.
- Use RemoteFunction only when cross-network request/response is truly needed and validate requests.
Runtime & versions
Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Luau documentation