secure_call Asynchronous
syn.secure_call
Run a callback in the context of a specified Script, LocalScript, or ModuleScript, then receive its results. It is useful when a callback must observe the same script environment as the code it accompanies.
Luau
secure_call(
callback: Function,
scriptOrOptions: ScriptInstance | SecureCallOptions,
...args: any
) -> ...anyParameters
| Parameter | Type | Description |
|---|---|---|
callback | Function | Function to run in the chosen script context. |
scriptOrOptions | ScriptInstance | SecureCallOptions | A script instance, or a table with Script and optional Environment and LineNumber fields. |
...args | any | Values forwarded to the callback. |
Argument fields
Luau
SecureCallOptions = {Script: ScriptInstance, Environment: Table?, LineNumber: number?}Returns
...anyAll values returned by the callback.
Usage notes
The script must be a valid script instance. If Environment is omitted, Kawaii obtains that script's environment.
The callback may yield; errors from validation or the callback propagate to the caller.
Example
Luau
local player = game:GetService("Players").LocalPlayer
local playerScripts = player and player:FindFirstChildOfClass("PlayerScripts")
local target = playerScripts and playerScripts:FindFirstChildWhichIsA("LocalScript")
if target then
local name = secure_call(function(value)
return value.Name
end, target, target)
print("Script context:", name)
end