pDataService - Advenced Data Managment for Roblox Games.
pDataService is a powerful data management module for Roblox that provides reliable data handling, automatic saving, backup functionality, and easy customization. It is designed to simplify data storage, versioning, and backup for player profiles and global data.
Please note that this module is still in BETA and may change in the future of course, every suggestion, review is aprecieted.
Developed by ParaTron Softworks.
Lead - Paradoxer
pDataService Features
- Automatic Data Saving - Automatically saves player profiles at configurable intervals.
- Backup System - Creates backups at set intervals to ensure data is preserved and can be restored if needed.
- Data Validation - Ensures that default values are applied if certain data keys are missing.
- Data Locking - Prevents data conflicts by locking profiles during critical operations.
- Global Data Management - Provides easy handling of global data storage.
- Customizable Save Intervals - Configure auto-save and backup intervals.
Basic Configuration
- Ungroup everything from folder,
Instructionsscript is where everything is explained where to put. - Open
pDataServiceModuleScript then changeDataStoreKeyto a unique string (change from"CHANGE_ME"to improve data security). - Configure the
AutoSaveIntervalandProfileBackupIntervalvalues as needed. - And you are done.
local pDataService = require(game.ReplicatedStorage:WaitForChild("pDataService"))
pDataService.DataStoreKey = "CHANGE_ME"
pDataService.AutoSaveInterval = 15 -- Save every 15 seconds
pDataService.ProfileBackupInterval = 600 -- Backup every 10 minutes
API
1. pDataService:GetDataStore(name)
Fetches a DataStore instance by name.
-
Parameters:
name(string) - The name of the DataStore. -
Returns:
DataStoreobject.
Example:
local playerStore = pDataService:GetDataStore("PlayerData")
2. pDataService:LoadProfile(playerId, defaultData)
Loads a player profile with default data if no existing data is found.
-
Parameters:
-
playerId(number) - Unique ID of the player. -
defaultData(table) - Default data to use if none exists.
-
-
Returns: Table of profile data or
nilif already loaded.
Example:
local defaultData = { coins = 0, level = 1 }
local playerProfile = pDataService:LoadProfile(player.UserId, defaultData)
3. pDataService:SaveProfile(playerId)
Saves a player’s profile data to DataStore. Automatically updates the last saved timestamp.
-
Parameters:
playerId(number) - Unique ID of the player. -
Returns:
trueif successful,falseotherwise.
Example:
pDataService:SaveProfile(player.UserId)
4. pDataService:ReleaseProfile(playerId)
Releases a player’s profile from memory when it is no longer needed.
-
Parameters:
playerId(number) - Unique ID of the player. - Returns: None.
Example:
pDataService:ReleaseProfile(player.UserId)
5. pDataService:SaveGlobalData(key, data)
Saves global data that applies across sessions.
-
Parameters:
-
key(string) - Unique key for the data. -
data(any) - Data to save.
-
-
Returns:
trueif successful,falseotherwise.
Example:
pDataService:SaveGlobalData("EventStatus", { started = true })
6. pDataService:LoadGlobalData(key, defaultData)
Loads global data or applies defaults if no data is found.
-
Parameters:
-
key(string) - Unique key for the data. -
defaultData(any) - Default data to use.
-
-
Returns: Retrieved data or
defaultDataif not found.
Example:
local eventStatus = pDataService:LoadGlobalData("EventStatus", { started = false })
7. pDataService:LockProfile(playerId)
Locks a profile to prevent other processes from accessing it until unlocked.
-
Parameters:
playerId(number) - Unique ID of the player. - Returns: None.
8. pDataService:UnlockProfile(playerId)
Unlocks a locked profile, allowing other processes to access it.
-
Parameters:
playerId(number) - Unique ID of the player. - Returns: None.
9. pDataService:BackupProfile(playerId)
Creates a backup of the player’s profile data.
-
Parameters:
playerId(number) - Unique ID of the player. - Returns: None.
Example:
pDataService:BackupProfile(player.UserId)
10. pDataService:IsProfileLocked(playerId)
Checks if a player’s profile is locked.
-
Parameters:
playerId(number) - Unique ID of the player. -
Returns:
trueif locked,falseotherwise.
Example:
if pDataService:IsProfileLocked(player.UserId) then
print("Profile is locked.")
end
Simple Usage Examples
Here’s a complete example of how to use pDataService to manage a player’s profile data with automatic saving and locking. For example i used Coins, Levels, and playtime for basic data to store.
Step 1: Loading and Saving Player Data
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local defaultData = { coins = 0, level = 1, playtime = 0 }
local playerProfile = pDataService:LoadProfile(player.UserId, defaultData)
if playerProfile then
print(player.Name .. "'s profile loaded!")
end
end)
Players.PlayerRemoving:Connect(function(player)
pDataService:SaveProfile(player.UserId)
pDataService:ReleaseProfile(player.UserId)
end)
Step 2: Using the Locking Mechanism
local function giveCoins(player, amount)
if pDataService:IsProfileLocked(player.UserId) then
print("Profile locked, try again later.")
return
end
pDataService:LockProfile(player.UserId)
local profile = pDataService.ActiveProfiles[player.UserId]
if profile then
profile.data.coins = profile.data.coins + amount
print("Coins updated for:", player.Name)
end
pDataService:UnlockProfile(player.UserId)
end
Step 3: Managing Global Data
-- Setting global data for an event
pDataService:SaveGlobalData("EventStatus", { started = true, description = "Halloween Event" })
-- Loading global data
local eventStatus = pDataService:LoadGlobalData("EventStatus", { started = false })
print("Event started:", eventStatus.started)
Code Configuration
- DataStoreKey: A unique string to prefix data entries. Changing this will reset all saved data unless updated in the DataStore.
- AutoSaveInterval: Time (in seconds) between each automatic save cycle for player profiles.
- ProfileBackupInterval: Time (in seconds) between each automatic backup cycle for player profiles.
Example Config:
NOTE: This configuration part can be found on top of pDataService
pDataService.DataStoreKey = "SOMETHING"
pDataService.AutoSaveInterval = 20 -- Saves every 20 seconds
pDataService.ProfileBackupInterval = 600 -- Backups every 10 minutes
TIPS
-
Always Set a Unique DataStoreKey: Ensure your data is isolated and secure by setting a unique
DataStoreKey. - Use Locking for Data Integrity: Use the locking functions when performing multiple or critical updates on profiles.
-
Configure Save and Backup Intervals: Adjust the
AutoSaveIntervalandProfileBackupIntervalbased on server needs and data importance.
