> ## 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.

# writefile

Writes `data` to the file at `path`. Any old contents are replaced. If folders in the path don't exist yet, they're created too.

```luau theme={null}
writefile(path: string, data: string): ()
```

`path` is workspace-relative. Don't put `"workspace/"` in front of it, and `"../"` won't get you out of the sandbox.

## Parameters

| Parameter | Type     | Description                                               |
| --------- | -------- | --------------------------------------------------------- |
| `path`    | `string` | File to write.                                            |
| `data`    | `string` | The string to write. Bytes go in as-is, no encoding step. |

## Returns

<code title="the function does not return a value.">void</code>

## Example

Save the script's settings as JSON:

<CodeGroup>
  ```luau Example 1 theme={null}
  <<<<<<< HEAD
  writefile("hello.txt", "Hello, world!")
  =======
  -- writefile(path: string, data: string): ()
  >>>>>>> 50e30f53759b0538759af25c9b271514aa2c9290
  ```

  ```luau Example 2 theme={null}
  local HttpService = game:GetService("HttpService")

  local config = {
      option1 = "apple",
      option2 = math.huge,
      option3 = 3735928559,
  }

  writefile("autofarm/config.json", HttpService:JSONEncode(config))
  ```
</CodeGroup>

<Tip>
  `writefile` always overwrites. Want to add to a file instead of replacing it? Use `appendfile`.
</Tip>
