loadfile
Compiles a saved Luau script without running it.
Syntax
Signature
loadfile(Path: string) -> (function?, string?)Aliases
This function has no aliases.
Parameters
| Parameter | Type | Description |
|---|---|---|
Path | string | Path relative to the sandboxed Workspace. |
Returns
| Type | Description |
|---|---|
function? | Compiled function, or nil when loading fails. |
string? | Loader error on failure. |
Notes
Returns nil and the loader error if the chunk cannot be loaded. Filesystem errors are raised.
Example
Luau
writefile("Example.luau", "return 42")
local Function, Error = loadfile("Example.luau")
assert(Function, Error)
print(Function())