Workspace & Auto-Execute

The folder your scripts read and write, and how to run a script automatically when you join.

How the folder is set up

Every file function is relative to the workspace folder next to the client. Paths can't go outside it, so readfile("../secrets.txt") just fails.

FolderWhat's in there
workspace/Where every path in readfile, writefile and the rest starts from.
autoexec/Scripts in here run every time you join a game.
scripts/Where the editor saves tabs by default, and what the file explorer shows.
assets/Not required, just a tidy place for images and fonts you use with getcustomasset.

Auto-execute

Put a .lua or .txt file in autoexec/ and it runs every time you join, in the order the folder lists them. Most people load their hub or a personal script this way.

autoexec/always.lua
-- autoexec/always.lua
-- Runs on every join. Keep it defensive: the game may not
-- be fully loaded when this fires.
if not game:IsLoaded() then
    game.Loaded:Wait()
end

local Players = game:GetService("Players")
local me = Players.LocalPlayer

warn(("joined %s as %s"):format(game.PlaceId, me.Name))

-- Only load the heavy stuff in the places it is meant for.
if game.PlaceId == 1234567890 then
    loadstring(readfile("scripts/that-game.lua"))()
end

Autoexec runs before you can stop it

A broken script in autoexec/ runs on every join. If you start getting errors the second you load in, empty the folder and add things back one at a time.

Reading and writing

The filesystem chapter has everything. Short version:

files.lua
-- Write, read back, append.
writefile("notes.txt", "first line\n")
appendfile("notes.txt", "second line\n")
print(readfile("notes.txt"))

-- Folders and listings.
if not isfolder("logs") then
    makefolder("logs")
end
for _, path in ipairs(listfiles("logs")) do
    print(path)
end

-- Load Luau straight off disk.
local chunk = loadfile("scripts/util.lua")
if chunk then chunk() end

Custom assets

getcustomasset turns a workspace file into an rbxasset:// URL Roblox can render, so you can put a local image on an ImageLabel or a Drawing object.

assets.lua
local url = getcustomasset("assets/crosshair.png")

local gui = Instance.new("ScreenGui", gethui())
local image = Instance.new("ImageLabel", gui)
image.Image = url
image.Size = UDim2.fromOffset(32, 32)
image.BackgroundTransparency = 1