readfileasync Asynchronous

Read a workspace file without blocking the game while the bytes load. Use it for larger files where readfile would stall a frame.

Syntax
Luau
readfileasync(path: string) -> string

Parameters

Function parameters
ParameterTypeDescription
pathstringWorkspace-relative path of the file to read.

Returns

string

The complete file contents as a binary-safe string.

Usage notes

The file work runs on a background thread, and the call always yields at least one frame, even for a small file. Filesystem failures raise in the calling thread.

Call it from a thread that may yield, such as a script body or a task.spawn function.

Example

Example
Luau
writefile("async-read.txt", "Loaded in the background")
local contents = readfileasync("async-read.txt")
print(contents)
delfile("async-read.txt")