Methods
An overview of all the methods available on both DataService and DataController.
GET Methods
Methods for getting player data, can be used on both client and server with the same code structure.
GetProfile
Gets all the data from a player, though on client it will not return data that has not been replicated.
Parameters:
player : Player -> Player who you want the data profile from.
timeOut : number? -> Max amount of time it will wait for the data (default is infinite).
usePromise : boolean? -> If set to true, it returns a promise instead and won't yield your code.
Returns a player profile, if successful.
Examples:
Not using promise:
Using promise:
GetData
Gets a specific data from a player based on the data name, will return nil if you attempt to get a data that is not being replicated to the client or that does not exist in its profile.
Parameters:
player : Player -> Player who you want the data from.
dataName : string -> Name of the data you want to get from the player.
timeOut : number? -> Max amount of time it will wait for the data (default is infinite).
usePromise : boolean? -> If set to true, it returns a promise instead and won't yield your code.
Returns the data requested, if successful.
Examples:
Not using promise:
Using promise:
POST Methods
Methods used to edit data, only available in the Server side, which means through DataService.
Add
Used to add into a number type data (pretty much doing a Data + Number).
Parameters:
player : Player -> Player who you want to modify the data.
dataName : string -> Name of the data.
value : number -> Value that will get added into the data, must NOT be negative.
Returns the new Data Value, if successful.
Example:
Increasing a player's coins by 5:
Sub
Used to subtract from a number type data (pretty much doing a Data - Number).
Parameters:
player : Player -> Player who you want to modify the data.
dataName : string -> Name of the data.
value : number -> Value that will get subtracted from the data, must NOT be negative.
Returns the new Data Value, if successful.
Example:
Decreasing a player's coins by 5:
Set
Used to edit any data in the player, completely overwriting any old one that was previously in the same data name.
Parameters:
player : Player -> Player who you want to modify the data.
dataName : string -> Name of the data.
value : any-> Value that will get set into the data, overwriting the old one.
Returns the new Data Value, if successful.
Example:
Setting a player's coins to 100:
ArrayInsert
Used to insert a value into an array type data.
Parameters:
player : Player -> Player who you want to modify the data.
dataName : string -> Name of the data.
value : any-> Value that will get inserted into the data.
Returns the new Data Value, if successful.
Example:
Inserting a Premium gamepass reference into a player's "Gamepasses" data:
ArrayRemove
Used to remove a data value from an array type data through the value index.
Parameters:
player : Player -> Player who you want to modify the data.
dataName : string -> Name of the data.
index : number -> Numeric index of the value you want to remove from the data.
Returns the new Data Value, if successful.
Example:
Removing a Premium gamepass reference from a player's "Gamepasses" data:
ArraySet
Used to set a data into the given array, overwriting any old values inside it.
Parameters:
player : Player -> Player who you want to modify the data.
dataName : string -> Name of the data.
value : {any} -> Value that will get set into the data, overwriting the old one.
Returns the new Data Value, if successful.
Examples:
Setting a player's gamepasses data to have VIP and Premium:
DictionaryInsert
Inserts a value inside a dictionary type of data, based on the given index.
Parameters:
player : Player -> Player who you want to modify the data.
dataName : string -> Name of the data.
value : number -> Value that will get set into the index, overwriting the old one.
index : number | string -> The index that the value will get inserted at, will overwrite any value that might be in the same index.
Returns the new Data Value, if successful.
Examples:
Inserting a sword item into a player's inventory:
DictionaryRemove
Removes a value from a dictionary type of data, based on its index.
Parameters:
player : Player -> Player who you want to modify the data.
dataName : string -> Name of the data.
index : number | string -> Index of the value to be removed.
Returns the new Data Value, if successful.
Examples:
Removing a sword from a player's inventory, following the same context of the DictionaryInsert example:
Bindings
Methods for binding callbacks whenever a specific data changes, or even all data, of a given player. It can also be used on both DataController and DataService.
Bind
Binds a callback to be run whenever the given data is changed in the given player.
Parameters:
player : Player -> Player who you want the data profile from.
dataName : string -> Data name to bind, whenever it changes it will trigger the callback.
callback : function -> function to be run whenever the data changes.
Doesn't really return anything.
Example:
Printing the player EXP whenever it gets changed:
Bind
Binds a callback to be run whenever any data of given player is changed.
Parameters:
player : Player -> Player who you want the data profile from.
callback : function -> function to be run whenever the data changes.
Doesn't really return anything.
Example:
Printing whenever any data of the player is changed:
Last updated