Hi, i was doing a data system using ProfileService and ReplicaService (all made by @loleris), but when i tested it out with a payout loop, my text that displays how much money i have didnt change even, though i scripted it for it to change, i did everything correctly (i think) and it didnt print the error message in the output.
i dont have any idea for what was the problem or i missed any parameters.
also heres the script i used:
Server Script:
local Settings = {
ProfileTemplate = {
Money = 100,
BloxCoins = 0,
},
}
local ServerScriptService = game:GetService("ServerScriptService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PhysicsService = game:GetService("PhysicsService")
local ProfileService = require(ServerScriptService.Utils.ProfileService)
local ReplicaService = require(ServerScriptService.Utils.ReplicaService)
local DataWriteLib = ReplicatedStorage.Modules.DataWriteLib
local ProfileStore = ProfileService.GetProfileStore("PlayerData", Settings.ProfileTemplate)
local ProfileToken = ReplicaService.NewClassToken("ProfileData")
local PlayerProfile
local PlayerProfiles = {}
local function PlayerAdded(player : Player)
local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId, "ForceLoad")
if profile ~= nil then
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
PlayerProfiles[player].Replica:Destroy()
PlayerProfiles[player] = nil
player:Kick()
end)
if player:IsDescendantOf(Players) == true then
local player_profile = {
Profile = profile,
Replica = ReplicaService.NewReplica({
ClassToken = ProfileToken,
Tags = {Player = player},
Data = profile.Data,
Replication = player,
WriteLib = DataWriteLib,
}),
_player = player,
}
setmetatable(player_profile, PlayerProfile)
PlayerProfiles[player] = player_profile
for i = 1, 10, 1 do -- payout loop
print("Payout "..i)
PlayerProfile:GiveMoney(100)
end
else
profile:Release()
end
else
player:Kick()
end
-- removing 2 players collision
player.CharacterAdded:Connect(function(character)
for _, bodypart in pairs(character:GetChildren()) do
if bodypart:IsA("BasePart") then
bodypart.CollisionGroup = "PlayerCharacters"
end
end
end)
end
PlayerProfile = {
}
PlayerProfile.__index = PlayerProfile
function PlayerProfile:GiveMoney(cash_amount : number)
if self:IsActive() == false then return end
self.Replica:Write("AddMoney", cash_amount)
end
function PlayerProfile:GiveBloxCoins(bloxcoin_amount : number)
if self:IsActive() == false then return end
self.Replica:Write("AddBloxCoins", bloxcoin_amount)
end
function PlayerProfile:IsActive()
return PlayerProfile[self._player] ~= nil
end
Players.PlayerAdded:Connect(PlayerAdded)
for _, player in Players:GetPlayers() do
coroutine.wrap(PlayerAdded)(player)
end
Players.PlayerRemoving:Connect(function(player)
local Profile = PlayerProfiles[player].Profile
if not Profile then return end
Profile:Release()
end)
inside datawritelib: (if your confused on line 15)
local WriteLib = {
AddMoney = function(replica, money_amount)
replica:SetValue({"Money"}, replica.Data.Money + money_amount)
end,
AddBloxCoins = function(replica, bloxcoins_amount)
replica:SetValue({"BloxCoins"}, replica.Data.BloxCoins + bloxcoins_amount)
end,
}
return WriteLib
Client Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MainFrame = script.Parent
local ReplicaController = require(ReplicatedStorage.Modules.ReplicaController)
ReplicaController.ReplicaOfClassCreated("ProfileData", function(replica)
MainFrame.MoneyCount.Text = replica.Data.Money
MainFrame.BloxCoinCount.Text = replica.Data.BloxCoins
replica:ListenToChange({"Money"}, function(new_value)
MainFrame.MoneyCount.Text = new_value
end)
replica:ListenToChange({"BloxCoins"}, function(new_value)
MainFrame.BloxCoinCount.Text = new_value
end)
end)
ReplicaController.RequestData()