DataStore2 not loading backup save


local DataStore2 = require(script.DataStore2)

local DataFolder = {
	Key = "DataFolder!",
	ID = 06743422368000989898000999299999999,
	
	_DATA_FOLDER = {
		Key = "DATA_TEMPLATE",
		
		Test = {One=6,Two=8,Three=9,Four=0, yes99=false},
		Catalog = {
			AA = {"Yes", "lol", 9},
			BB = false,
			["yes"] = 9,
		},
	},
	
}

DataStore2.Combine("DATAFOLDER_KEY" .. 1, DataFolder.Key, DataFolder._DATA_FOLDER.Key) --key, item, item

local TemplateStore = DataStore2(DataFolder._DATA_FOLDER.Key, DataFolder.ID):Get(nil) --WE MUST BE ABLE TO GET A TEMPLATE.
if TemplateStore ~= nil then
	print(DataStore2(DataFolder._DATA_FOLDER.Key, DataFolder.ID):Get())
else
	warn("[ Data2 ]: No previous data for: " .. DataFolder._DATA_FOLDER.Key .. ".")

--
	DataStore2(DataFolder._DATA_FOLDER.Key, DataFolder.ID):Set(DataFolder._DATA_FOLDER)
	DataStore2(DataFolder._DATA_FOLDER.Key, DataFolder.ID):SetBackup(9, DataFolder._DATA_FOLDER)
	DataStore2(DataFolder._DATA_FOLDER.Key, DataFolder.ID):Save(DataFolder._DATA_FOLDER)
	warn("[ Data 2 ]: New save has been created.")
--]]
end

DataStore2:

--Public functions

function DataStore:Get(defaultValue, dontAttemptGet)
	if dontAttemptGet then
		return self.value
	end
	
	local backupCount = 0

	if not self.haveValue then
		while not self.haveValue do
			task.wait(math.random(0,2)) --EDITED BY BILLY.
			local success, error = self:_GetRaw():await()
			
--DONT LOAD ON PURPOSE SO THAAT THE SCRIPT CAN GEET THE BACKUP DATA BELLOW.
		--[	EDITED BY BILLYBOBTYJOSEPH
			print("l", self.backupRetries, self, DataStore)
			success = nil
			self.haveValue = nil
			--]] 
			
			if not success then
         --GEET THE FREAKING BACK UP SAVE?!
				if self.backupRetries then
--self.backupretries = nil????
					backupCount = backupCount + 1

					if backupCount >= self.backupRetries then
						self.backup = true
						self.haveValue = true
						self.value = self.backupValue
						warn("[ DataStore2 ]: Back-up save has been activated for: " .. self.Name)
						break;
					end
				end

				self:Debug("Get returned error:", error)
			end
			
		end

		if self.value ~= nil then
			for _,modifier in pairs(self.beforeInitialGet) do
				self.value = modifier(self.value, self)
			end
		end
	end

	local value

	if self.value == nil and defaultValue ~= nil then --not using "not" because false is a possible value
		value = defaultValue
	else
		value = self.value
	end
	
	--print(value, " LOADEDEDED")  --EDITED BY BILLY
	value = clone(value)
	
	self.value = value

	return value
end

DAATASTORE2w.rbxl (57.9 KB)

WHY DOES SELF.BACKUPRETRIES = nil? I’m using this correctly. Self doesnt even print the same thing based on whatever uses it. help

Would it be possible to see the code where you create the DataStore object? Your DataStore.new() function or equivalent.

Yes it’s all right there. Also if you wish to see more I left a download that has the 2 scripts. The Datastore.new is at the very top. When the function is called at the very beginning

Sorry in advance for the lengthy answer

I’m looking through your DataStore2 script, I can’t find any method which returns self.

From what I’ve seen so far, this is required. I might be wrong about that however.

Usually the code is something along the following lines:

local MyObject = {}
MyObject.__index = Object-- Tell missing indexes to search through this object

function MyObject.new()
    local self = {} -- Create self
   
    setmetatable(self, MyObject) -- Set references to Object within 'self'
    return self -- Return this specific instance of the MyObject object
end

return MyObject

You may already know this, and I might be missing another crucial detail; but the following hopefully explains the difference between functions with . and : respectively.

-- Lua
function MyObject.foo()
    -- This function does *not* know about self.
    -- Works more or less the same as a regular module script.
        -- (will act the same no matter which MyObject called it)
    ...
end

function MyObject:bar()
    -- This function *does* know about self.
    -- Can be seen as a function of this MyObject instance
        -- (may act differently depending on which MyObject called it)
    ...
end

I’m not sure how familiar you are with other programming languages, but if you know Java this might be able to help:

public static void foo() {
    ...
}

public void bar() {
    ...
}

If any of this is incorrect, feel free to correct me.

2 Likes