# Custom Data Module \[🔜]

{% hint style="warning" %}

## FEATURE IS CURRENTLY NOT RELEASED

This feature is pending release and is not available in any public versions. Please check back soon, this feature will be in Version 7!
{% endhint %}

{% hint style="info" %}

## USAGE WARNINGS

* This feature **is classed as advanced** and is only recommended to use if you understand what to do
* This feature **can cause your data stores to fail/break**. Please use this in a seperate Roblox project during set up to avoid unexpected problems. Please remember to test you changes thoroughly
* This feature has been labeled as Experimental, the feature is likely to have flaws and will recieve more capability updates in the future.
  {% endhint %}

### What is this feature?

Custom Data Module allows a developer to redirect player data to a Module Script rather then the normal Roblox DataStoresService. This is often used in high daily active players game's to manipulate the data saving process for features such as data loss prevention however can be used for other features dependent on what you script or the script you are using.\
\
Due to how advanced this is and failing to set up correctly can cause the system to break, I'd recommend following the tutorial below OR using the preset below which uses ProfileStore.

### Settings Classes

<table><thead><tr><th width="208.24530029296875">Name</th><th width="174.8116455078125">Type</th><th>Function</th></tr></thead><tbody><tr><td>DataModule</td><td>Folder</td><td>The folder to place the ModuleScript that will act as the DataStores. If non or more then 2 then defaults to DataStoresService.</td></tr><tr><td>GetDataFunction</td><td>String</td><td>The function string that the ModuleScript requires to get player data</td></tr><tr><td>GetDataVariables</td><td>String (To act as table)</td><td>The values and refrences that the Module Script get function requires.<br><br>This acts as a string of table so you MUST follow the information in Obtainable Variables and splitting must be done by ", "</td></tr><tr><td>SetDataFunction</td><td>String</td><td>The function string that the ModuleScript requires to set/update player data</td></tr><tr><td>SetDataVariables</td><td>String (To act as table)</td><td>The values and refrences that the Module Script set function requires.<br><br>This acts as a string of table so you MUST follow the information in Obtainable Variables and splitting must be done by ", "</td></tr><tr><td>StartupFunction</td><td>String</td><td>OPTIONAL - </td></tr><tr><td>StartupVariables</td><td>String</td><td>OPTIONAL -</td></tr><tr><td>CombineFunction</td><td>String</td><td></td></tr><tr><td>CombineVariables</td><td>String (To act as table)</td><td><br><br>This acts as a string of table so you MUST follow the information in Obtainable Variables and splitting must be done by ", "</td></tr><tr><td>StartCombineFunction</td><td>String</td><td></td></tr><tr><td>StartCombineVariables</td><td>String (To act as table)</td><td><br><br>This acts as a string of table so you MUST follow the information in Obtainable Variables and splitting must be done by ", "</td></tr></tbody></table>

### How to set up

1. Firstly, place your module script that will act as the data store to the 'DataModule' folder. Ensure that it is a ModuleScript (purple script) to avoid errors
2. Next, Change GetDataFunction value to the string of the function used to retrieve the player data and do this for SetDataFunction.
3. Lastly, Check what veriables are required for the function and refer to the possible variables list below for help on refrencing. Make sure that there is a comma (, ) and space in between each to avoid errors.

### Auto-Complete Setup

The AutocompleteSetup bool setting allows you to have the system automatically fill in the functions infomation. This feature currently requires you to be using a supported Module and the ModuleScript name must remain the same from what it was originally named. All data infomation is viewable in the module parented however do not make any changes or else it could break the system and you won't be able to recieve automatic updates.

Additionally, the data retrieved for this feature is set to always check and recieve updates by default so when a new data module is rolled out to this feature, it will be live for all games using it without requiring to download the latest version.

**Supported DataModules:**

| Module Name | Date Added | Package Version Required |
| ----------- | ---------- | ------------------------ |
| DataStores2 | UNKNOWN    | 7                        |

{% hint style="warning" %}

## To recieve auto-updates, you must get the download version because Roblox toolbox models are not allowed to have package links. NOT REQUIRED

{% endhint %}

### Pre-Intergrated Templates

Within this feature, I've also included a folder called "Pre-IntergratedTemplates" which includes data modules that supports Auto-Complete Setup and/or has had modifications made to it that allows it to be better integrated to whats already possible with SimpleDataStores package.

The contents of this will NOT be able to recieve live updates like Auto-Complete Setup so if a new data module support is released and you want the intergrated version, you'll need to get it from the up to date package however this feature is less likely to recieve new content nore should you need new content due to what it already supports.

{% hint style="warning" %}

## To recieve auto-updates, you must get the download version because Roblox toolbox models are not allowed to have package links. NOT REQUIRED

{% endhint %}

### Obtainable Variables

| Variable     | Type         | Returns                                                                                           | Available for                 |
| ------------ | ------------ | ------------------------------------------------------------------------------------------------- | ----------------------------- |
| player       | Instance     | Returns the local player instance (may require .UserId to get the User ID)                        | Set, Get, Combine and Startup |
| UserID       | String       | Returns the string version of the local player UserId                                             | Set, Get, Combine and Startup |
| playerstats  | Table        | Returns the raw table that is trying to be saved                                                  | Set                           |
| leaving      | Bool         | Returns true if the player is leaving the game and false if the player is resetting/dead          | Set                           |
| backpackonly | Bool         | Returns true if the game only want's the player backpack and false if it wants all player data    | Get                           |
| DataStore    | ModuleScript | Returns the Module Script being used for Custom Data Module. If non then returns DataStoreService | Set, Get, Combine and Startup |
| GetData      | String       | Returns the function string used to fire GetData                                                  | Set, Get and Startup          |
| SetData      | String       | Returns the function string used to fire SetData                                                  | Set, Get and Startup          |

### Possible Errors

Error Information: Output Debugging enabled is not required to recieve any of these errors, when an error occours, the script will automatically switch back to Roblox DataStoresService to prevent further errors.

| Error Message                                                                                                                 | Reason                                                                                                                    | Solution                                                                                                                                                                                                          |
| ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Only 1 instance can be in DataModule folder. Please ensure that there is only 1 ModuleScript in DataModule Folder             | There is 2 or more instances/scripts in the DataModule folder                                                             | Only have 1 ModuleScript in DataModule folder                                                                                                                                                                     |
| Module Script not found in DataModule folder                                                                                  | There is something in DataModule folder but it's not a ModuleScript                                                       | Replace what's in DataModule folder with a ModuleScript and ensure it does not return nil.                                                                                                                        |
| DataStore could not be set up correctly. Please follow the documentation or DevForums post for more infomation on how to fix. | The system experienced an error when requiring the module script.                                                         | Make sure the ModuleScript returns something except nil or you may be experiencing a Roblox related problem like an outage.                                                                                       |
| Failed to find matching AutoCompleteSetup within available data                                                               | <ol><li>The ModuleScript is not named exact</li><li>The DataModule is not currently available for Auto-Complete</li></ol> | <ol><li>Check the MainModule in AutocompleteSetup and name based on the infomation</li><li>Report the DataModule via the DevForums to be added to Auto-Complete OR manually set up using tools provided</li></ol> |

### Limitations

{% hint style="warning" %}

### Feature Limitations

The following features are **NOT** available currently with CustomDataModule!

* SaveOnDeath (Does not work with new "changes" saving method, working on this ASAP)

\
The following features **may require modifications** to the ModuleScript to work correctly (unless not required or using pre-intergrated templates)

* SaveInStudio - Some ModuleScripts might require diffrent methods to allow this to work and may require extra steps
* DataStoreName - Some ModuleScripts might have a pre-selected/hard coded data store name
  {% endhint %}
