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

# dofile

Reads the file at `path` and runs it as Luau code. Whatever the file sets - locals, globals, even `_G` - stays in the file.

```luau theme={null}
dofile(path: string): ()
```

`path` is workspace-relative. The file must contain valid Luau source (not bytecode). Use `loadfile` when you want to inspect the chunk or call it more than once - `dofile` always runs it exactly once and throws the return values away.

## Parameters

| Parameter | Type     | Description                  |
| --------- | -------- | ---------------------------- |
| `path`    | `string` | Luau source file to execute. |

## Returns

<code title="the function does not return a value.">void</code> - anything the file returns is discarded.

## Example

Save a script to a file, then run it:

<CodeGroup>
  ```luau Example 1 theme={null}
  <<<<<<< HEAD
  dofile("script.luau")
  =======
  -- dofile(path: string): ()
  >>>>>>> 50e30f53759b0538759af25c9b271514aa2c9290
  ```

  ```luau Example 2 theme={null}
  writefile("scripts/setup.luau", [[
      print("setup ran")
      return "ok"
  ]])

  dofile("scripts/setup.luau")
  ```
</CodeGroup>

<Tip>
  Variables declared inside the file don't leak into the calling environment. If you need to share state, write to a known table (e.g. `getgenv().myVariable = ...`) inside the file and read it back from the caller.
</Tip>
