ProfileNetwork - Data Interface for ProfileService!

ProfileNetwork

a **ProfileNetwork** is a module made by [SilentsReplacement](https://www.roblox.com/users/700264840/profile). It is a robust data interface for [ProfileService](https://devforum.roblox.com/t/save-your-player-data-with-profileservice-datastore-module/667805) and provides methods which come in really handy when working towards proper data management and control.

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)
3 Likes

Your documentation is null.

While looking at the model, I notice there’s not much to it. It’s just a ProfileService proxy. It would be cool if it was something that handled data maybe via players and did the job of releasing profiles and everything.

1 Like

No, it’s your job to handle profiles, the point of this module is to make data management with ProfileService easier.