Hello! I recently switched to profile service, and some problems started occur. Certain values reset to 0, or even go to minus. I watched the MonzterDev tutorial on how to set up the Profile Service. I triple checked all the scripts related to saving and adding values and everything seems to be okay.
Let me give you an example.
This is the save/load part: (i add the “stats” folder in a different script)
local Players = game:GetService("Players")
local Template = require(script.Parent.Template)
local ProfileService = require(script.Parent.ProfileService)
local Manager = require(script.Parent.Manager)
local ProfileStore = ProfileService.GetProfileStore("3", Template)
local function GiveLeaderstats(player: Player)
local profile = Manager.Profiles[player]
if not profile then return end
local Money = player.Stats.Money
Money.Value = profile.Data.Money
end
local function PlayerAdded(player: Player)
local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
if profile == nil then
player:Kick("Data issue, try again shortly. If issue persists, contact us!")
return
end
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
Manager.Profiles[player] = nil
player:Kick("Data issue, try again shortly. If issue persists, contact us!")
end)
if player:IsDescendantOf(Players) == true then
Manager.Profiles[player] = profile
else
profile:Release()
end
GiveLeaderstats(player)
end
for _, player in ipairs(Players:GetPlayers()) do
task.spawn(PlayerAdded, player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(player: Player)
local profile = Manager.Profiles[player]
if not profile then return end
profile:Release()
end)
And this is the adding part:
game.Players.PlayerAdded:Connect(function(Player)
while task.wait(1) do
local Manager = require(game.ServerScriptService.PlayerData.Manager)
local profile = Manager.Profiles[Player]
Player.Stats.Money.Value +=1
profile.Data.Money +=1
end
end)
Any idea why this could be happening?