dofile
Compiles and runs a workspace Luau file, returning its results. Unlike loadfile, execution happens immediately. Compilation and runtime errors propagate to the caller; wrap the operation in pcall when recovery is needed.
Syntax
dofile(path: string) -> ...any
Also available as
do_file
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Workspace-relative source file. |
Returns
| Type | Description |
|---|---|
...any | Values returned by the file. |
Description
File operations are confined to the current workspace. Absolute paths and traversal outside it are not accepted. Use a file dialog when the user needs to choose an external file.
Example
writefile("example.luau", "return 2 + 3")
print(dofile("example.luau"))
These are Game executor contracts. Check build requirements and session lifetimes before using them.
