> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# loadfile

> Reads a workspace file, compiles its contents with the Luau compiler, and returns the loaded Luau function without executing it.

<div className="real-function-page">
  ```lua theme={null}
  loadfile(path: string, chunkName?: string): function | nil | string | nil
  ```

  ## Aliaslar

  * `loadfileasync`
  * `dofile`
  * `dofileasync`

  ## Argümanlar

  <ParamField path={"path"} type={"string"} required>
    File path resolved inside the workspace after separator normalization, workspace-boundary checks, and extension checks. Path, open, and read-size errors are thrown.
  </ParamField>

  <ParamField path={"chunkName"} type={"string"}>
    Optional chunk name passed to luau\_load. Defaults to = when omitted or nil.
  </ParamField>

  ## Dönüşler

  <ResponseField name={"chunk"} type={"function | nil"}>
    Loaded Luau function when luau\_load succeeds. The function is not executed by loadfile.
  </ResponseField>

  <ResponseField name={"errorMessage"} type={"string | nil"}>
    Error string returned as the second value only when luau\_load fails. Filesystem and path errors are thrown instead.
  </ResponseField>

  ## Örnek

  Bir workspace Luau file degerini function olarak yukleyin, sonra kendiniz cagirin.

  ```lua theme={null}
  writefile("examples/module.luau", "return 2 + 3")

  local chunk, message = loadfile("examples/module.luau", "ExampleModule")

  if chunk then
      print(chunk())
  else
      warn(message)
  end
  ```
</div>
