# GlobalDataStore

Roblox Engine API class from Roblox Studio 0.744.0.7441077 (version-7aaa6838d36c4448).

- Inherits from, nearest first: [Instance](https://rapi.sleaze.dev/classes/Instance.md), [Object](https://rapi.sleaze.dev/classes/Object.md)
- Subclasses: [DataStore](https://rapi.sleaze.dev/classes/DataStore.md), [OrderedDataStore](https://rapi.sleaze.dev/classes/OrderedDataStore.md)
- Tags: Not creatable, Not replicated
- Memory category: Instances
- HTML page: https://rapi.sleaze.dev/classes/GlobalDataStore/
- Roblox documentation: https://create.roblox.com/docs/reference/engine/classes/GlobalDataStore

An object that exposes methods to access a single data store.

## Methods

### BatchGetAsync

```luau
GlobalDataStore:BatchGetAsync(keys: { any }, options: { [string]: any }? = nil): { [string]: any }
```

- Tags: Yields, Capabilities: DataStore

Returns the values of multiple keys from the data store in a single request.

Parameters:

- `keys`: An array of key name strings to retrieve. The maximum number of keys per request is determined by a server-side limit (default 100).
- `options`: **(Optional)** Unused; has no effect.

Returns: A dictionary mapping each requested key (string) to a table containing a `value` field with the key's current value. Keys that don't exist or have no value are omitted from the result.

### GetAsync

```luau
GlobalDataStore:GetAsync(key: string, options: DataStoreGetOptions? = nil): ...any
```

- Tags: Yields, Capabilities: DataStore

Returns the value of a key in a specified data store and a [`DataStoreKeyInfo`](https://rapi.sleaze.dev/classes/DataStoreKeyInfo.md) instance.

Parameters:

- `key`: The key name for which the value is requested. If [`DataStoreOptions.AllScopes`](https://rapi.sleaze.dev/classes/DataStoreOptions.md) was set to true when accessing the data store through [`DataStoreService:GetDataStore()`](https://rapi.sleaze.dev/classes/DataStoreService.md), this key name must be prepended with the original scope as in "scope/key".
- `options`: **(Optional)** A [`DataStoreGetOptions`](https://rapi.sleaze.dev/classes/DataStoreGetOptions.md) instance that controls aspects of the read, such as whether to bypass the locally cached value via its [`DataStoreGetOptions.UseCache`](https://rapi.sleaze.dev/classes/DataStoreGetOptions.md) property.

Returns: The value of the entry in the data store with the given key and a [`DataStoreKeyInfo`](https://rapi.sleaze.dev/classes/DataStoreKeyInfo.md) instance that includes the version number, date and time the version was created, and functions to retrieve `UserIds` and metadata.

### IncrementAsync

```luau
GlobalDataStore:IncrementAsync(key: string, delta: number? = 1, userIds: { any }? = {}, options: DataStoreIncrementOptions? = nil): any
```

- Tags: Yields, Capabilities: DataStore

Increments the value of a key by the provided amount (both must be integers).

Parameters:

- `key`: Key name for which the value should be updated. If [`DataStoreOptions.AllScopes`](https://rapi.sleaze.dev/classes/DataStoreOptions.md) was set to true when accessing the data store through [`DataStoreService:GetDataStore()`](https://rapi.sleaze.dev/classes/DataStoreService.md), this key name must be prepended with the original scope as in "scope/key".
- `delta`: Amount to increment the current value by.
- `userIds`: **(Optional)** A table of `UserIds` to associate with the key.
- `options`: **(Optional)** [`DataStoreIncrementOptions`](https://rapi.sleaze.dev/classes/DataStoreIncrementOptions.md) instance that combines multiple additional parameters as custom metadata and allows for future extensibility.

Returns: The updated value of the entry in the data store with the given key.

### RemoveAsync

```luau
GlobalDataStore:RemoveAsync(key: string): ...any
```

- Tags: Yields, Capabilities: DataStore

Removes the specified key while also retaining an accessible version.

Parameters:

- `key`: Key name to be removed. If [`DataStoreOptions.AllScopes`](https://rapi.sleaze.dev/classes/DataStoreOptions.md) was set to true when accessing the data store through [`DataStoreService:GetDataStore()`](https://rapi.sleaze.dev/classes/DataStoreService.md), this key name must be prepended with the original scope as in "scope/key".

Returns: The value of the data store prior to deletion and a [`DataStoreKeyInfo`](https://rapi.sleaze.dev/classes/DataStoreKeyInfo.md) instance that includes the version number, date and time the version was created, and functions to retrieve `UserIds` and metadata.

### SetAsync

```luau
GlobalDataStore:SetAsync(key: string, value: any, userIds: { any }? = {}, options: DataStoreSetOptions? = nil): any
```

- Tags: Yields, Capabilities: DataStore

Sets the value of the data store for the given key.

Parameters:

- `key`: Key name for which the value should be set. If [`DataStoreOptions.AllScopes`](https://rapi.sleaze.dev/classes/DataStoreOptions.md) was set to true when accessing the data store through [`DataStoreService:GetDataStore()`](https://rapi.sleaze.dev/classes/DataStoreService.md), this key name must be prepended with the original scope as in "scope/key".
- `value`: The value that the data store key will be set to.
- `userIds`: Table of `UserIds`, highly recommended to assist with GDPR tracking/removal.
- `options`: **(Optional)** [`DataStoreSetOptions`](https://rapi.sleaze.dev/classes/DataStoreSetOptions.md) instance that allows for metadata specification on the key.

Returns: The version identifier of the newly created version. It can be used to retrieve key info using `GetVersionAsync()` or to remove it using `RemoveVersionAsync()`.

### UpdateAsync

```luau
GlobalDataStore:UpdateAsync(key: string, transformFunction: (...any) -> ...any): ...any
```

- Tags: Yields, Capabilities: DataStore

Updates a key's value with a new value from the specified callback function.

Parameters:

- `key`: Key name for which the value should be updated. If [`DataStoreOptions.AllScopes`](https://rapi.sleaze.dev/classes/DataStoreOptions.md) was set to true when accessing the data store through [`DataStoreService:GetDataStore()`](https://rapi.sleaze.dev/classes/DataStoreService.md), this key name must be prepended with the original scope as in "scope/key".
- `transformFunction`: Transform function that takes the current value and [`DataStoreKeyInfo`](https://rapi.sleaze.dev/classes/DataStoreKeyInfo.md) as parameters and returns the new value along with optional `UserIds` and metadata.

Returns: The updated value of the entry in the data store with the given key and a [`DataStoreKeyInfo`](https://rapi.sleaze.dev/classes/DataStoreKeyInfo.md) instance that includes the version number, date and time the version was created, and functions to retrieve `UserIds` and metadata.

### OnUpdate

```luau
GlobalDataStore:OnUpdate(key: string, callback: (...any) -> ...any): RBXScriptConnection
```

- Tags: Deprecated, Capabilities: DataStore

**Deprecated:** This function has been deprecated and should not be used in new work. You can use the `Cross Server Messaging Service` to publish and subscribe to topics to receive near real-time updates, completely replacing the need for this function.

Sets a callback function to be executed any time the value associated with a key is changed.

Parameters:

- `key`: The key identifying the entry being retrieved from the data store.
- `callback`: The function to be executed any time the value associated with **key** is changed.

Returns: The connection to the key being tracked for updates.

## Inherited members

- From [Instance](https://rapi.sleaze.dev/classes/Instance.md): `Archivable`, `archivable`, `Attributes`, `AttributesReplicate`, `AttributesSerialize`, `HistoryId`, `Name`, `Parent`, `PredictionMode`, `PropertyStatusStudio`, `RobloxLocked`, `SerializedOverrides`, `SourceAssetId`, `Tags`, `UniqueId`, `numExpectedDirectChildren`, `DataCost`, `Capabilities`, `DefinesCapabilities`, `IsInSandbox`, `Sandboxed`, `AddTag`, `ClearAllChildren`, `Clone`, `Destroy`, `FindFirstAncestor`, `FindFirstAncestorOfClass`, `FindFirstAncestorWhichIsA`, `FindFirstChild`, `FindFirstChildOfClass`, `FindFirstChildWhichIsA`, `FindFirstDescendant`, `GetActor`, `GetAttribute`, `GetAttributeChangedSignal`, `GetAttributes`, `GetChildren`, `GetDebugId`, `GetDescendants`, `GetFullName`, `GetStyled`, `GetStyledPropertyChangedSignal`, `GetTags`, `HasTag`, `IsAncestorOf`, `IsDescendantOf`, `IsPropertyModified`, `QueryDescendants`, `RemoveTag`, `ResetPropertyToDefault`, `SetAttribute`, `WaitForChild`, `Remove`, `children`, `clone`, `destroy`, `findFirstChild`, `getChildren`, `isDescendantOf`, `remove`, `AncestryChanged`, `AttributeChanged`, `ChildAdded`, `ChildRemoved`, `DescendantAdded`, `DescendantRemoving`, `Destroying`, `StyledPropertiesChanged`, `childAdded`
- From [Object](https://rapi.sleaze.dev/classes/Object.md): `ClassName`, `className`, `GetPropertyChangedSignal`, `IsA`, `isA`, `Changed`
