Hi there!
So I’ve got this data saving system, which converts folders, strings, numbers, etc into tables to save them into a data store. The saving is completely fine, but when a player joins the game the data just entirely breaks.
Below I’ve shown what happens before you rejoin and after, as well as the scripts that load the data on rejoining as I assume it’s the one causing issues.
Note: Profile Service is used for data saving
Before Leaving:
Original Data:
Original Converted Data:
After Rejoining
Messed up data:
Converted Data:
Scripts used to load data:
local function createData(data, parent)
for dataLabel, dataValue in pairs(data) do
warn(dataLabel, dataValue)
local type = dataTypeToInstanceType(typeof(dataValue))
if type == "Folder" then
local DataInstance = createInstance(type, {Name = dataLabel})
createData(dataValue, DataInstance)
DataInstance.Parent = parent
else
local DataInstance = createInstance(type, {Name = dataLabel, Value = dataValue})
DataInstance.Parent = parent
end
end
end
function Data.CreatePlayerDataInstances(Player, Profile : {}?)
Profile = Profile or Data.LoadedProfiles[Data.CreateProfileKey(Player)]
Profile.Data.CashOutRate = tonumber(Profile.Data.CashOutRate)
print(Profile.Data.Games)
local DataFolder = Instance.new("Folder")
DataFolder.Name = "Stats"
local LeaderStats = createInstance("Folder", {Name = "leaderstats", Parent = Player})
local FakeCash = createInstance("StringValue", {Value = Profile.Data.Cash, Parent = LeaderStats, Name = "Cash"})
local FakeVisits = createInstance("StringValue", {Value = Profile.Data.AllTimeVisits, Parent = LeaderStats, Name = "Visits"})
print("PROFILE ON ENTRY: ",Profile.Data)
createData(Profile.Data, DataFolder)
DataFolder.Parent = Player
local Playtime = DataFolder.Playtime
task.spawn(function()
while game.Players:FindFirstChild(Player.Name) do
Playtime.Value += 1
task.wait(1)
end
end)
end
I have no clue why this is happening, and I’ve tried to implement things to try and fix it, but they all end up with the same result.
If anyone has any ideas on why this is happening and how to fix it, please let me know. Thanks!