Not able to backup data

Hi, I have an issue with my data not being able to detect currency.
I am using ProfileService a DataManagement API made by loleris.

Problem:
Unable To Backup Data

if backupProfile ~= nil then
	if not table.find(lockedData,player.Name) then
		local function DataReadyForBackup()
			local function Check(args)
				local item = ""
				for i = 1 ,#args do
					item = item..'["'..args[i]..'"]'
							
					print(profile.Data["Currency"]) --Prints out {["Coins"] = 0, ["Diamonds"] = 0}
					if profile.Data[item] == nil then --Error Here! The Script should not be going through this check.. since item is == ["Currency"]
						print(profile.Data)
						print(item) --Prints out ["Currency"]
						return false
					end
				end
				print(true)
				return true
			end
			local BackupCheck = {
				{"Currency","Coins"},
				{"Currency","Diamonds"},
				
			}
					
			for i,v in pairs(BackupCheck) do
				if not Check(v) then
					return false
				end
			end
					
			return true
		end
		if profile.Data ~= nil then
			if DataReadyForBackup() then
				backupProfile.Data = profile.Data
				print("Backup Data Updated.")
				backupProfile:Release()
			else
				warn("Unable To Backup Data") --The game outputs this.
				backupProfile:Release()
			end
		else
			warn("Player Data Corrupted")
			backupProfile:Release()
		end
	else
		warn("Data is locked")
	end
else
	warn("Backup Profile Not Available")
end

The immediate issue is this line: item = item..'["'..args[i]..'"]'

profile.Data["Currency"] is what you are attempting to access (I think), but based on that line above, you are instead accessing profile.Data["[Currency]"] (note the extra brackets).

Additionally, the second iteration will have item set to "[Currency][Coins]", which also probably isn’t what you intended.


I might be misunderstanding what you’re trying to do here, but if I assume correctly, you can change your Check closure to this:

local function Check(args)
	local item = profile.Data
	for _, arg in ipairs(args) do
		item = item[arg]
		if not item then return false end
	end
end
1 Like