Service for accessing and storing persistent data for a map.

WARNING: Yielding in an Event will delay the outcome of the event. All DataStoreService functions WILL yield the current thread.

It is highly recommended to use task.spawn()around all DataStoreService functions. An example is provided below.

Example usage:

-- Double the score of a player whenever they kill an entity
local function doubleScore(current)
    return current * 2

Events.EntityDeath(function (event)
    local killerPlayer = event.killer:getPlayer()
    if (killerPlayer == nil) then
        local currentValue = DataStoreService.getAsync(killerPlayer.userId)
        if (currentValue == nil) then
            currentValue = 1
        DataStoreService.setAsync(killerPlayer.userId, doubleScore(currentValue))


getAsync(key: string | number): any

Returns the latest stored value for the given key.

setAsync(key: string | number, value: any): bool

Sets the latest value for the given key. Returns true if the network call was successful.

incrementAsync(key: string | number, amount: number): bool

Increases the current integer value for the given key by the given amount (must also be an integer value). Returns true if the network call was successful.

removeAsync(key: string | number): bool

Marks the given key as deleted. Returns true if the network call was successful.

Last updated