@rbxts/lyra
v0.6.1
Published
A DataStoreService wrapper
Readme
The @rbxts/lyra module is not maintained by paradoxum-games and is a personally maintained fork by @6ixfalls.
Lyra makes it easy to safely and robustly manage your game's player data. It's designed to handle large amounts of data, prevent common game-breaking bugs, and make it easy to update your data format without breaking existing saves.
Early Development
While Lyra has been tested and is used in production, it's still in early development. Some features, like transactions, while tested in controlled environments, have not yet been battle-tested in production at scale.
Avoid using Lyra in production games where data loss would be catastrophic until it has been tested more thoroughly.
Fork Note
This module is maintained relatively sporadically as I don't currently use @rbxts/lyra in my own games. Use at your own risk; Review the source as needed.
This fork aims to maintain the least amount of additional code and as a result, no changes to the .luau files are done except when necessary to support roblox-ts as an architecture. TypeScript typings match the .luau types.
Ping @sixfalls in the roblox-ts Discord for any support or issues with using the package.
Features
- Transactions - A powerful tool to implement features like trading, while making bugs like item duplication impossible
- Session Locking - Prevents common bugs that lead to corruption and data loss
- Validation - Ensures your data is always in a consistent state
- Auto-Sharding - Handles large data by automatically splitting across multiple DataStore keys
- Migrations - Update your data format without breaking existing saves
- Drop-in - Import your existing data and switch over seamlessly
Quick Start
local store = Lyra.createPlayerStore({
name = "PlayerData",
template = {
coins = 0,
inventory = {},
},
schema = t.strictInterface({
coins = t.number,
inventory = t.table,
}),
})
-- Load data when players join
Players.PlayerAdded:Connect(function(player)
store:loadAsync(player)
end)
-- Free up resources when players leave
Players.PlayerRemoving:Connect(function(player)
store:unloadAsync(player)
end)
-- Update data
store:updateAsync(player, function(data)
data.coins += 100
return true
end)
-- Atomic transactions
store:txAsync({player1, player2}, function(state)
local amount = 50
state[player1].coins -= amount
state[player2].coins += amount
return true
end)TS examples
import { t } from "@rbxts/t";
import Lyra from "@rbxts/lyra";
import { Players } from "@rbxts/services";
const store = Lyra.createPlayerStore({
name: "PlayerData",
template: {
coins: 0,
inventory: {},
},
schema: t.strictInterface({
coins: t.number,
inventory: t.table,
}),
});
// Load data when players join
Players.PlayerAdded.Connect((player) => {
store.loadAsync(player);
});
// Free up resources when players leave
Players.PlayerRemoving.Connect((player) => {
store.unloadAsync(player);
});
// Update data
store.updateAsync(player, (data) => {
data.coins += 100;
return true;
});
// Atomic transactions
store.txAsync([player1, player2], (state) => {
const amount = 50;
state.get(player1).coins -= amount;
state.get(player2).coins += amount;
return true;
});Installation
Add to your wally.toml:
Lyra = "paradoxum-games/[email protected]"Check out the documentation for guides, examples, and API reference.
