Locking
Mode
Description
Locking Patterns
Airship.Players.onPlayerJoined.Connect(async (player) => {
const result = await Platform.Server.DataStore.LockKeyOrStealSafely(
`progress:${player.userId}`
);
if (!result) player.Kick("Unable to load progress.");
// You can now safely read and write to this key. No other server
// can read or modify it.
this.progress[player.userId] = await Platform.Server.DataStore.GetKey(
`progress:${player.userId}`
);
});
Airship.Players.onPlayerDisconnected.Connect(async (player) => {
await Platform.Server.DataStore.SetKey(
`progress:${player.userId}`,
this.progress[player.userId],
);
delete this.progress[player.userId];
// Release the key when the player disconnects.
await Platform.Server.DataStore.UnlockKey(`progress:${player.userId}`);
});
Platform.Server.Transfer.onShutdown.Connect(() => {
Promise.allSettled(ObjectUtils.keys(this.progress).map(async userId => {
await Platform.Server.DataStore.SetKey(
`progress:${player.userId}`,
this.progress[player.userId],
);
await Platform.Server.DataStore.UnlockKey(
`progress:${player.userId}`
);
})).expect();
});Last updated