local F=60 local u=true local A=true function onPlayerEntered(F)local u=Instance.new("\070\111\108\100\101\114")u.Parent=DataFolder u.Name=F.UserId local A=DataFolder.Data:clone()A.Parent=DataFolder[F.UserId]local l=A:GetChildren()local I={}for F=1,#l,1 do local u=l[F].Name I[u]=l[F].Value end local H=DataStoreService:GetDataStore(F.userId)if H:GetAsync("\083\097\118\101")==nil then local F,u=pcall(function()H:SetAsync("\083\097\118\101",I)end)if F then print("\068\097\116\097 \115\097\118\101\100 \099\111\114\114\101\099\116\108\121")else print("\069\114\114\111\114\058 "..u)end end local i,o=pcall(function()I=H:GetAsync("\083\097\118\101")end)if i then print("\068\097\116\097 \114\101\099\101\105\118\101\100 \099\111\114\114\101\099\116\108\121")else print("\069\114\114\111\114\058 "..o)end local Y=A:GetChildren()for F=1,#Y,1 do local u=Y[F].Name if I[u]~=nil then Y[F].Value=I[u]end end end game.Players.PlayerAdded:connect(onPlayerEntered)if A then game.Players.PlayerRemoving:connect(function(F)local u=DataStoreService:GetDataStore(F.userId)local A=DataFolder[F.UserId].Data:GetChildren()local l={}for F=1,#A,1 do local u=A[F].Name l[u]=A[F].Value end local I,H=pcall(function()u:SetAsync("\083\097\118\101",l)end)if I then print("\068\097\116\097 \115\097\118\101\100 \099\111\114\114\101\099\116\108\121")else print("\069\114\114\111\114\058 "..H)end DataFolder[F.UserId]:Destroy()end)end local l={}if u==true then while wait(1)do for u,A in pairs(game.Players:GetPlayers())do if not l[A]then l[A]=tick()elseif tick()-l[A]>=F then print("\083\097\118\101\100")l[A]=tick()local F=DataStoreService:GetDataStore(A.userId)local u=DataFolder[A.UserId].Data:GetChildren()local I={}for F=1,#u,1 do local A=u[F].Name I[A]=u[F].Value end local H,i=pcall(function()F:SetAsync("\083\097\118\101",I)end)if H then print("\068\097\116\097 \115\097\118\101\100 \099\111\114\114\101\099\116\108\121")else print("\069\114\114\111\114\058 "..i)end end end end end
--//Settings\--
local Save_Wait_Time = 60
local Auto_Save = true
local Save_On_Leave = true

function onPlayerEntered(newPlayer)
	local datafolder = Instance.new("Folder")
	datafolder.Parent = DataFolder
	datafolder.Name = newPlayer.UserId
	local DataValue = DataFolder.Data:clone()
	DataValue.Parent = DataFolder[newPlayer.UserId]
	local Data = DataValue:GetChildren()
	local DataTable = {}
	for i = 1, #Data do
		local n = Data[i].Name
		DataTable[n] = Data[i].Value
	end
	--GetData--
	local DataStore = DataStoreService:GetDataStore(newPlayer.userId)
	if DataStore:GetAsync("Save") == nil then
		local succeed, errormsg = pcall(function()
			DataStore:SetAsync("Save", DataTable)
		end)
		if succeed then
			print("Data saved correctly")
		else
			print("Error: " .. errormsg)
		end
	end

	local succeed, errormsg = pcall(function()
		DataTable = DataStore:GetAsync("Save")
	end)
	if succeed then
		print("Data received correctly")
	else
		print("Error: " .. errormsg)
	end
	--LoadData--
	local DataToLoad = DataValue:GetChildren()
	for i = 1, #DataToLoad do
		local n = DataToLoad[i].Name
		if DataTable[n] ~= nil then
			DataToLoad[i].Value = DataTable[n]
		end
	end
end

game.Players.PlayerAdded:connect(onPlayerEntered)

if Save_On_Leave then
	game.Players.PlayerRemoving:connect(function(Player)
		--SaveData--
		local DataStore = DataStoreService:GetDataStore(Player.userId)
		local Data = DataFolder[Player.UserId].Data:GetChildren()
		local DataTable = {}
		for i = 1, #Data do
			local n = Data[i].Name
			DataTable[n] = Data[i].Value
		end
		local succeed, errormsg = pcall(function()
			DataStore:SetAsync("Save", DataTable)
		end)
		if succeed then
			print("Data saved correctly")
		else
			print("Error: " .. errormsg)
		end
		DataFolder[Player.UserId]:Destroy()
	end)
end

local DataSaveTable = {}

if Auto_Save == true then
	while wait(1) do
		for _, Player in pairs(game.Players:GetPlayers()) do
			if not DataSaveTable[Player] then
				DataSaveTable[Player] = tick()
			elseif tick() - DataSaveTable[Player] >= Save_Wait_Time then
				print("Saved")
				DataSaveTable[Player] = tick()
				local DataStore = DataStoreService:GetDataStore(Player.userId)
				local Data = DataFolder[Player.UserId].Data:GetChildren()
				local DataTable = {}
				for i = 1, #Data do
					local n = Data[i].Name
					DataTable[n] = Data[i].Value
				end
				local succeed, errormsg = pcall(function()
					DataStore:SetAsync("Save", DataTable)
				end)
				if succeed then
					print("Data saved correctly")
				else
					print("Error: " .. errormsg)
				end
			end
		end
	end
end
