Documentation: Documentation
Source: Source
Roblox model: Roblox Model
Benefits
-
Light weight - With optimized code, this module doesn’t do anything expensive and conserves memory.
-
Robust Data Interface - Robust data interface which easily allows you to handle profiles.
-
User friendly - Easy to use module and straight forward, no need to waste a lot of time learning how to work with this module.
- Flexibility - Allows you to create your own methods on top of existing ones, without any headaches.
Want to get a new feature implemented? Consider creating a Issue on the repository.
Example usage
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ProfileNetwork = require(ServerStorage.ProfileNetwork)
local ProfileStore = ProfileNetwork.new("TestStore", {Cash = 0})
local function HandleProfileLoad(player, profile)
if (profile) then
profile:Reconcile() -- Fill in missing variables from ProfileTemplate (optional)
profile.OnRelease:Connect(function()
-- The profile could've been loaded on another Roblox server:
player:Kick()
end)
if (player:IsDescendantOf(Players) == false) then
profile:Release()
end
else
-- The profile couldn't be loaded
player:Kick("Your profile couldn't be loaded")
end
end
local function PlayerAdded(player)
local profile = ProfileStore:LoadProfile(player.Name, false, "ForceLoad")
HandleProfileLoad(player, profile) -- handle profile loading
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = profile.Data.Cash
cash.Parent = leaderstats
leaderstats.Parent = player
profile.OnUpdate:Connect(function(key, value) -- listen to when the profile updates
leaderstats[key].Value = value
end)
profile:Set("Cash", cash.Value + 5) -- increment 5 cash
end
local function PlayerRemoving(player)
ProfileStore:GetCachedProfile(player.Name):Release() -- release the profile
end
-- Get new players:
Players.PlayerAdded:Connect(PlayerAdded)
-- Get current players:
for _, player in ipairs(Players:GetPlayers()) do
coroutine.wrap(PlayerAdded)(player)
end
-- Get leaving players:
Players.PlayerRemoving:Connect(PlayerRemoving)