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.
💾 Cloud Data Persistence
Section titled “💾 Cloud Data Persistence”Lau provides 3 dedicated save slots (1, 2, and 3) for your persistent data.
| Function | Arguments | Description |
|---|---|---|
data.save(slot, list) | number, list | Saves a table to the specified slot. |
data.load(slot) | number | Returns the table stored in that slot, or null. |
data.clear(slot) | number | Permanently deletes all data in that slot. |
Example: Saving & Loading Settings
Section titled “Example: Saving & Loading Settings” lau-compiler.exe
varol mySettings = { speed = 25, autoSell = true }
-- Save to slot 1data.save(1, mySettings)print("[Data] Settings saved to Slot 1!")
-- Load it backvarol loaded = data.load(1)print("[Data] Loaded Speed: " + loaded.speed)OUTPUT:
[Data] Settings saved to Slot 1!
[Data] Loaded Speed: 25
🛡️ Error Handling (pcall)
Section titled “🛡️ Error Handling (pcall)”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.
| Returns | Type | Description |
|---|---|---|
success | boolean | true if the function ran without errors. |
result | any | The return value of the function OR the error message. |
Why use pcall?
Section titled “Why use pcall?”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 + bend
-- Run the function inside a pcallvarol success, result = pcall(dangerousMath, 10, 5)
print("Success: " + success)print("Result: " + result)OUTPUT:
Success: true
Result: 15
💡 Practical Example: Safe Data Loader
Section titled “💡 Practical Example: Safe Data Loader”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)