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.

Syntax
Luau
secure_call(
    callback: Function,
    scriptOrOptions: ScriptInstance | SecureCallOptions,
    ...args: any
) -> ...any

Parameters

Function parameters
ParameterTypeDescription
callbackFunctionFunction to run in the chosen script context.
scriptOrOptionsScriptInstance | SecureCallOptionsA script instance, or a table with Script and optional Environment and LineNumber fields.
...argsanyValues forwarded to the callback.

Argument fields

SecureCallOptions fields
Luau
SecureCallOptions = {Script: ScriptInstance, Environment: Table?, LineNumber: number?}

Returns

...any

All 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

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
Kawaii documentation