function DataStore.Save(k)if not k.valueUpdated then warn(("\068\097\116\097 \115\116\111\114\101 \037\115 \119\097\115 \110\111\116 \115\097\118\101\100 \097\115 \105\116 \119\097\115 \110\111\116 \117\112\100\097\116\101\100\046"):format(k.name))return end if game.VIPServerId~=""then return end if(game:GetService("\082\117\110\083\101\114\118\105\099\101")):IsStudio()and not SaveInStudio then warn(("\068\097\116\097 \115\116\111\114\101 \037\115 \097\116\116\101\109\112\116\101\100 \116\111 \115\097\118\101 \105\110 \115\116\117\100\105\111 \119\104\105\108\101 \083\097\118\101\073\110\083\116\117\100\105\111 \105\115 \102\097\108\115\101\046"):format(k.name))if not SaveInStudioObject then warn("\089\111\117 \099\097\110 \115\101\116 \116\104\101 \118\097\108\117\101 \111\102 \116\104\105\115 \098\121 \099\114\101\097\116\105\110\103 \097 \066\111\111\108\086\097\108\117\101 \110\097\109\101\100 \083\097\118\101\073\110\083\116\117\100\105\111 \105\110 \083\101\114\118\101\114\083\116\111\114\097\103\101\046")end return end if k.backup then warn("\084\104\105\115 \100\097\116\097 \115\116\111\114\101 \105\115 \097 \098\097\099\107\117\112 \115\116\111\114\101\044 \097\110\100 \116\104\117\115 \119\105\108\108 \110\111\116 \098\101 \115\097\118\101\100\046")return end if k.value~=nil then local l=clone(k.value)if k.beforeSave then local E,D=pcall(k.beforeSave,l,k)if E then l=D else warn("\069\114\114\111\114 \111\110 \066\101\102\111\114\101\083\097\118\101\058 "..D)return end end if not Verifier.warnIfInvalid(l)then return warn("\073\110\118\097\108\105\100 \100\097\116\097 \119\104\105\108\101 \115\097\118\105\110\103")end local E=(k.mostRecentKey or 0)+1 k.dataStore:SetAsync(E,l)k.orderedDataStore:SetAsync(E,E)k.mostRecentKey=E for E,D in pairs(k.afterSave)do local v,g=pcall(D,l,k)if not v then warn("\069\114\114\111\114 \111\110 \065\102\116\101\114\083\097\118\101\058 "..g)end end print("\115\097\118\101\100 "..k.name)end end

function DataStore:Save()
	if not self.valueUpdated then
		warn(("Data store %s was not saved as it was not updated."):format(self.name))
		return
	end
	
	if game.VIPServerId ~= "" then
		return
	end

	if game:GetService("RunService"):IsStudio() and not SaveInStudio then
		warn(("Data store %s attempted to save in studio while SaveInStudio is false."):format(self.name))
		if not SaveInStudioObject then
			warn("You can set the value of this by creating a BoolValue named SaveInStudio in ServerStorage.")
		end
		return
	end

	if self.backup then
		warn("This data store is a backup store, and thus will not be saved.")
		return
	end

	if self.value ~= nil then
		local save = clone(self.value)

		if self.beforeSave then
			local success, newSave = pcall(self.beforeSave, save, self)

			if success then
				save = newSave
			else
				warn("Error on BeforeSave: "..newSave)
				return
			end
		end

		if not Verifier.warnIfInvalid(save) then return warn("Invalid data while saving") end

		local key = (self.mostRecentKey or 0) + 1
		self.dataStore:SetAsync(key, save)
		self.orderedDataStore:SetAsync(key, key)
		self.mostRecentKey = key

		for _, afterSave in pairs(self.afterSave) do
			local success, err = pcall(afterSave, save, self)

			if not success then
				warn("Error on AfterSave: "..err)
			end
		end

		print("saved "..self.name)
	end
end
