I have been having issues with rollbacks happening when they don’t need to. I am quite new to profile store, and any help would be appreciated.
Complants: (FC is a currency)
1:
I had 483 FC, but when I died and created another match, I had 412 (the number I started the last match)
I don’t know if this is normal or a bug.
2:
i had 300 faz coins and rejoined and it converted to 63 coins i think it bought my classes again
Lobby code
lobby loading code:
local playerFolder = storeFolder:FindFirstChild(Player.Name)
local newData = Profile.Data
if not playerFolder then
local folder = defaultFolder:Clone(); folder.Name = Player.Name; folder.Parent = storeFolder
playerFolder = folder
end
local bestNight = BestNightService:GetAsync(Player.UserId) or 0
local TopDonated = TopDonatedService:GetAsync(Player.UserId) or 0
local FazCoins = Instance.new("NumberValue")
FazCoins.Name = "FazCoins"
FazCoins.Parent = playerFolder
FazCoins.Value = newData.FazCoins or 0
local EquippedClass = Instance.new("StringValue")
EquippedClass.Name = "EquippedClass"
EquippedClass.Parent = playerFolder
EquippedClass.Value = newData.EquippedClass or "None"
Player:SetAttribute("EquippedClass", newData.EquippedClass or "None")
Player:SetAttribute("FazCoins", newData.FazCoins or 0)
Player:SetAttribute("BestNight", bestNight)
Player:SetAttribute("Donated", TopDonated)
local Connections = {}
Connections[1] = FazCoins.Changed:Connect(function()
Player:SetAttribute("FazCoins", FazCoins.Value)
end)
Connections['end'] = Player.AncestryChanged:Connect(function()
for _, Connection in Connections do
Connection:Disconnect()
end
end)
Connections[3] = Player.CharacterAdded:Connect(function(Character)
-- // Give player their over head labels // --
HandleNametags(Player, Profile)
end)
if Player.Character then
HandleNametags(Player, Profile)
end
local OwnedClasses = Instance.new("Folder")
OwnedClasses.Name = "OwnedClasses"
OwnedClasses.Parent = playerFolder
local OwnedClassesList = newData.OwnedClasses or {}
for _, Class in OwnedClassesList do
local ClassValue = Instance.new("StringValue")
ClassValue.Name = Class
ClassValue.Parent = OwnedClasses
end
if #OwnedClassesList >= 1 then
if not BadgeService:UserHasBadgeAsync(Player.UserId, 3784697066131220) then
BadgeService:AwardBadgeAsync(Player.UserId, 3784697066131220)
end
end
if #OwnedClassesList >= 10 then
if not BadgeService:UserHasBadgeAsync(Player.UserId, 3782647163983712) then
BadgeService:AwardBadgeAsync(Player.UserId, 3782647163983712)
end
end
return playerFolder
all values in the lobby change the folder
Lobby saving code:
local PlayerFolder = storeFolder:FindFirstChild(Player.Name)
if PlayerFolder == nil then
profile:EndSession()
return
end
local FazCoins = if PlayerFolder:FindFirstChild("FazCoins") then PlayerFolder.FazCoins.Value else 0
local EquippedClass = if Player:GetAttribute("EquippedClass") then Player:GetAttribute("EquippedClass") else "None"
local OwnedClasses = if PlayerFolder:FindFirstChild("OwnedClasses") then PlayerFolder.OwnedClasses:GetChildren() else {}
local NewTable = {}
-- clear duplicates
for _, Class in profile.Data.OwnedClasses do
if table.find(NewTable, Class) == nil then
table.insert(NewTable, Class)
end
end
for _, Class in OwnedClasses do
if table.find(NewTable, Class.Name) == nil then
table.insert(NewTable, Class.Name)
end
end
profile.Data.OwnedClasses = NewTable
profile.Data.FazCoins = FazCoins
profile.Data.EquippedClass = EquippedClass
profile:EndSession()
TopDonatedService:UpdateAsync(Player.UserId, function(oldValue)
local newBest = Player:GetAttribute("Donated")
oldValue = oldValue or 0
if newBest > oldValue then
return newBest
end
return nil
end)
In game code
Loading:
local profile = PlayerStore:StartSessionAsync("Player_" .. Player.UserId, {
Cancel = function()
return Player.Parent ~= Players
end,
})
if profile ~= nil then
profile:AddUserId(Player.UserId)
profile:Reconcile()
profile.OnSessionEnd:Connect(function()
Profiles[Player] = nil
Player:Kick(`Profile session end - Please rejoin`)
end)
if Player.Parent == Players then
Profiles[Player] = profile
print(`Profile loaded for {Player.DisplayName}!`)
task.spawn(function()
MigrateData(Player, profile)
end)
Player:SetAttribute("FazCoins", profile.Data.FazCoins)
Player:SetAttribute("Class", profile.Data.EquippedClass)
Player:SetAttribute("Cash", workspace:GetAttribute("Game_MoneyEarnedOnSurvival"))
Player:SetAttribute("Shop", false)
Player:SetAttribute("Donated", TopDonatedService:GetAsync(Player.UserId))
else
profile:EndSession()
end
else
Player:Kick(`Profile load fail - Please rejoin`)
end
Saving:
local profile = Profiles[Player]
if profile ~= nil then
profile.Data.FazCoins = Player:GetAttribute("FazCoins")
profile:EndSession()
BestNightService:UpdateAsync(Player.UserId, function(oldValue)
local newBest = workspace:GetAttribute("DayCount")
oldValue = oldValue or 0
if newBest > oldValue then
return newBest
end
return nil
end)
TopDonatedService:UpdateAsync(Player.UserId, function(oldValue)
local newBest = Player:GetAttribute("Donated")
oldValue = oldValue or 0
if newBest > oldValue then
return newBest
end
return nil
end)
end
Any help is appreciated ![]()
![]()