loadfile
Compiles a workspace file into a callable chunk, returning nil plus an error message on failure.
Signature
loadfile(path: string, chunkName: string?): ((...any) -> ...any)?, string?Parameters
pathstringPath to the Luau file.
chunkNamestring?Optional name shown in tracebacks.
Returns
function?, string?
Example
writefile("hello.lua", 'print("loaded from a file")')
local chunk, err = loadfile("hello.lua")
if chunk then
chunk()
else
warn(err)
end