Hello! I’ve been using ProfileService for some time now, and i’ve noticed a issue with the saving. It seems to load old data instead of saving the data that the player has when leaving. I have only tested this in studio, but I do not think ProfileService should function this way, and I do not see anyone else with the same issue. If anyone can let me know if it saves data in intervals or just doesn’t save correctly in Roblox Studio, please do let me know!
Here are my scripts:
DataManager:
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local DataModules = ServerScriptService:WaitForChild("DataModules")
local ProfileService = require(DataModules:WaitForChild("ProfileService"))
local Template = require(script:WaitForChild("Template"))
local Items = require(script:WaitForChild("Items"))
local DataKey = "_DataStore"
local ProfileStore = ProfileService.GetProfileStore(DataKey,Template)
local dataManager = {}
dataManager.Profiles = {}
local function PlayerAdded(player: Player)
local Profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
if Profile then
Profile:AddUserId(player.UserId)
Profile:Reconcile()
Profile:ListenToRelease(function()
dataManager.Profiles[player] = nil
player:Kick("There was a data store issue! Please report this bug in our communications server if rejoining does not work for you.")
end)
if player:IsDescendantOf(Players) then
dataManager.Profiles[player] = Profile
Items:Create(player,Profile)
else
Profile:Release()
end
else
player:Kick("There was a data store issue! Please report this bug in our communications server if rejoining does not work for you.")
end
end
local function PlayerRemoving(player: Player)
local Profile = dataManager.Profiles[player]
if Profile ~= nil then
Profile:Release()
end
end
for _, player in Players:GetPlayers() do
task.spawn(PlayerAdded,player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)
return dataManager
Items:
local module = {}
function module:Create(player: Player, profile)
local CurrentTroll = Instance.new("StringValue")
CurrentTroll.Name = "CurrentTroll"
CurrentTroll.Parent = player
local Trolls = Instance.new("Folder")
Trolls.Name = "Trolls"
Trolls.Parent = player
local Items = Instance.new("Folder")
Items.Name = "Items"
Items.Parent = player
local Banned = Instance.new("BoolValue")
Banned.Name = "Banned"
Banned.Parent = player
---
local Troll1 = Instance.new("StringValue")
Troll1.Name = "Troll1"
Troll1.Parent = Trolls
local Troll2 = Instance.new("StringValue")
Troll2.Name = "Troll2"
Troll2.Parent = Trolls
local Troll3 = Instance.new("StringValue")
Troll3.Name = "Troll3"
Troll3.Parent = Trolls
local Troll4 = Instance.new("StringValue")
Troll4.Name = "Troll4"
Troll4.Parent = Trolls
local Troll5 = Instance.new("StringValue")
Troll5.Name = "Troll5"
Troll5.Parent = Trolls
local Troll6 = Instance.new("StringValue")
Troll6.Name = "Troll6"
Troll6.Parent = Trolls
local Troll7 = Instance.new("StringValue")
Troll7.Name = "Troll7"
Troll7.Parent = Trolls
local Troll8 = Instance.new("StringValue")
Troll8.Name = "Troll8"
Troll8.Parent = Trolls
---
local Item1 = Instance.new("StringValue")
Item1.Name = "Item1"
Item1.Parent = Items
local Item2 = Instance.new("StringValue")
Item2.Name = "Item2"
Item2.Parent = Items
local Item3 = Instance.new("StringValue")
Item3.Name = "Item3"
Item3.Parent = Items
local Item4 = Instance.new("StringValue")
Item4.Name = "Item4"
Item4.Parent = Items
local Item5 = Instance.new("StringValue")
Item5.Name = "Item5"
Item5.Parent = Items
local Item6 = Instance.new("StringValue")
Item6.Name = "Item6"
Item6.Parent = Items
local Item7 = Instance.new("StringValue")
Item7.Name = "Item7"
Item7.Parent = Items
local Item8 = Instance.new("StringValue")
Item8.Name = "Item8"
Item8.Parent = Items
---
CurrentTroll.Value = profile.Data.CurrentTroll
Troll1.Value = profile.Data.Troll1
Troll2.Value = profile.Data.Troll2
Troll3.Value = profile.Data.Troll3
Troll4.Value = profile.Data.Troll4
Troll5.Value = profile.Data.Troll5
Troll6.Value = profile.Data.Troll6
Troll7.Value = profile.Data.Troll7
Troll8.Value = profile.Data.Troll8
Item1.Value = profile.Data.Item1
Item2.Value = profile.Data.Item2
Item3.Value = profile.Data.Item3
Item4.Value = profile.Data.Item4
Item5.Value = profile.Data.Item5
Item6.Value = profile.Data.Item6
Item7.Value = profile.Data.Item7
Item8.Value = profile.Data.Item8
Banned.Value = profile.Data.Banned
end
return module
Template:
local template = {
CurrentTroll = "Troll",
Troll1 = "Troll",
Troll2 = "Troll",
Troll3 = "Troll",
Troll4 = "Troll",
Troll5 = "Troll",
Troll6 = "Troll",
Troll7 = "Troll",
Troll8 = "Troll",
Item1 = "None",
Item2 = "None",
Item3 = "None",
Item4 = "None",
Item5 = "None",
Item6 = "None",
Item7 = "None",
Item8 = "None",
Banned = false,
}
return template
PlayerData:
local DataManager = require(script.Parent:WaitForChild("DataModules"):WaitForChild("DataManager"))
And of course, ProfileService is ProfileService.
Any help is appreciated!