Skip to content

Data Module & pcall

The data module allows you to store information that persists even after you leave the game or restart your script. To use this effectively, you must also understand how to handle errors safely.


Lau provides 3 dedicated save slots (1, 2, and 3) for your persistent data.

FunctionArgumentsDescription
data.save(slot, list)number, listSaves a table to the specified slot.
data.load(slot)numberReturns the table stored in that slot, or null.
data.clear(slot)numberPermanently deletes all data in that slot.
lau-compiler.exe
varol mySettings = { speed = 25, autoSell = true }
-- Save to slot 1
data.save(1, mySettings)
print("[Data] Settings saved to Slot 1!")
-- Load it back
varol loaded = data.load(1)
print("[Data] Loaded Speed: " + loaded.speed)
OUTPUT:
[Data] Settings saved to Slot 1! [Data] Loaded Speed: 25

A “Protected Call” (pcall) is a global function used to run a piece of code safely. If the code inside a pcall errors, the script will not stop. Instead, it returns a status message.

ReturnsTypeDescription
successbooleantrue if the function ran without errors.
resultanyThe return value of the function OR the error message.

You should use pcall when loading data or calling modules that might be missing, to ensure your drone stays active even if a single operation fails.

lau-compiler.exe
func dangerousMath(a, b)
return a + b
end
-- Run the function inside a pcall
varol success, result = pcall(dangerousMath, 10, 5)
print("Success: " + success)
print("Result: " + result)
OUTPUT:
Success: true Result: 15

This script attempts to load data. If the slot is empty or corrupted, it uses default values instead of crashing.

varol success, savedData = pcall(func()
return data.load(1)
end)
varol config = {}
if success AND savedData ~= null then
config = savedData
player.sent("Cloud data synced!")
else
-- Fallback to defaults
config = { speed = 10, mode = "basic" }
player.alert("Failed to load data. Using defaults.")
end
print("Drone speed set to: " + config.speed)