Saving a folders with values in the easiest way

What exactly happens? Most likely, if it is saved, the folders will just be duplicated, resulting in two identical folders

image
You’re right.
print(TableToSave) in end of the Players.PlayerRemoved = nothing

If you want, we can go somewhere else, and I didn’t notice at first, do you understand Russian?

Yes, im understand Russian and I don’t mind if we go somewhere else.

Ну тогда, можешь там в лс или куда то скинуть ДС допустим
Здесь просто такое себе думаю обьяснять будет

1 Like

Many thanks to these people for their help: BC_LMGG, NyrionDev, Cloudy71
Solution that created by BC_LMGG:

local DataStoreService = game:GetService("DataStoreService")
local STORE = DataStoreService:GetDataStore("STR12")

game.Players.PlayerAdded:Connect(function(Player)
	--LEADERSTATS
	local leaderstats= Instance.new("Folder")
	leaderstats.Name= ("leaderstats")
	leaderstats.Parent= Player
	local cash= Instance.new("IntValue",leaderstats)
	cash.Name= ("Wins")
	cash.Value = 0 
	local cash= Instance.new("IntValue",leaderstats)
	cash.Name= ("Money")
	cash.Value = 0 
	
	local cash= Instance.new("IntValue",leaderstats)
	cash.Name= ("PassXP")
	cash.Value = 0 
	--ABILITIES
	local leaderstats= Instance.new("Folder")
	leaderstats.Name= ("Abilities")
	leaderstats.Parent= Player
	local cash= Instance.new("BoolValue",leaderstats)
	cash.Name= ("Invisible")
	cash.Value =  false
	local cash= Instance.new("BoolValue",leaderstats)
	cash.Name= ("Speed")
	cash.Value =  false
	local cash= Instance.new("BoolValue",leaderstats)
	cash.Name= ("Radar")
	cash.Value =  false
	local cash= Instance.new("BoolValue",leaderstats)
	cash.Name= ("Shield")
	cash.Value =  false
	--DESTROYER FOLDER
	local DestroyerPapka= Instance.new("Folder")
	DestroyerPapka.Name= ("DestroyerFolder")
	DestroyerPapka.Parent= Player
	local cash= Instance.new("BoolValue",DestroyerPapka)
	cash.Name= ("SuperLauncher")
	cash.Value =  false
	local cash= Instance.new("BoolValue",DestroyerPapka)
	cash.Name= ("SuperBomb")
	cash.Value =  false
	local cash= Instance.new("BoolValue",DestroyerPapka)
	cash.Name= ("Flamethrower")
	cash.Value =  false
	local cash= Instance.new("BoolValue",DestroyerPapka)
	cash.Name= ("SuperFlamethrower")
	cash.Value =  false
	local cash= Instance.new("BoolValue",DestroyerPapka)
	cash.Name= ("SuperAxe")
	cash.Value =  false
	local Key = tostring(Player.UserId)
	local DataPlayer = STORE:GetAsync(Key)
	if DataPlayer ~= nil then
		--ASGSA
		for NameFolder,CheckFolder in pairs(DataPlayer) do
			OldFolder = Player:FindFirstChild(NameFolder)

			NewFolder = Instance.new("Folder")
			NewFolder.Name = NameFolder
			NewFolder.Parent = Player

			for _,CheckValue in pairs(CheckFolder) do
				local ThisVal = nil
				if CheckValue["TypeValue"] == "String" then
					local NewValue = Instance.new("StringValue")
					ThisVal = NewValue
				elseif CheckValue["TypeValue"] == "BoolValue" then
					local NewValue = Instance.new("BoolValue")
					ThisVal = NewValue
				elseif CheckValue["TypeValue"] == "IntValue" then
					local NewValue = Instance.new("IntValue")
					ThisVal = NewValue
				elseif CheckValue["TypeValue"] == "NumberValue" then
					local NewValue = Instance.new("NumberValue")
					ThisVal = NewValue
				end
				if ThisVal then
					ThisVal.Value = CheckValue["Value"]
					ThisVal.Name = CheckValue["NameValue"]
					ThisVal.Parent = NewFolder

				end
			end
			
				for _, CheckOldValue in pairs(OldFolder:GetChildren()) do
					if NewFolder:FindFirstChild(CheckOldValue.Name) == nil then
						CheckOldValue.Parent = NewFolder
					end
				end
			
			OldFolder:Destroy()
		end
		
	end
	print(DataPlayer)
end)
local BlackListSave = {

}
game.Players.PlayerRemoving:Connect(function(Player)
	local TableToSave = {}
	for _,CheckingFolder in pairs(Player:GetChildren()) do
		if CheckingFolder:IsA("Folder") then
			if table.find(TableToSave,CheckingFolder.Name) == nil then
				local TableToInst = {}
				table.insert(TableToSave,TableToInst)
				TableToSave[CheckingFolder.Name] = TableToSave[1]
				TableToSave[1] = nil
			end
			local ThisTable = TableToSave[CheckingFolder.Name]
			for _,CheckValue in pairs(CheckingFolder:GetChildren()) do
				if CheckValue:IsA("ValueBase") then
					if table.find(BlackListSave,CheckValue.Name) == nil then
						if ThisTable then
							if CheckValue:IsA("StringValue") then
								local ThisValue = {
									["TypeValue"] = "String",
									["NameValue"] = CheckValue.Name,
									["Value"] = CheckValue.Value
								}
								table.insert(ThisTable,ThisValue)
							elseif CheckValue:IsA("BoolValue") then
								local ThisValue = {
									["TypeValue"] = "BoolValue",
									["NameValue"] = CheckValue.Name,
									["Value"] = CheckValue.Value
								}
								table.insert(ThisTable,ThisValue)
							elseif CheckValue:IsA("IntValue") then
								local ThisValue = {
									["TypeValue"] = "IntValue",
									["NameValue"] = CheckValue.Name,
									["Value"] = CheckValue.Value
								}
								table.insert(ThisTable,ThisValue)
							elseif CheckValue:IsA("NumberValue") then
								local ThisValue = {
									["TypeValue"] = "NumberValue",
									["NameValue"] = CheckValue.Name,
									["Value"] = CheckValue.Value
								}
								table.insert(ThisTable,ThisValue)
								-- Else Value
							end
						end
					end
				end
			end
		end
	end
	local Key = tostring(Player.UserId)
	STORE:SetAsync(Key,TableToSave)
	print(TableToSave)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.