Help with datastore

theres already a folder in replicatedstorage, how can i save all of the values of the children in that folder

simple
btw changed the folder variable to your folder

local ds = game:GetService("DataStoreService"):GetDataStore("Test")

game.Players.PlayerAdded:Connect(function(plr)
	local folder = insertFolderVariableHere
	local values = ds:GetAsync(plr.UserId.."Values")
	for i,v in pairs(values) do
		for i,b in pairs(folder:GetChildren()) do
			if v.Name == b.Name then
				b.Value = v.Value
			end
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local folder = insertFolderVariableHere
	local toSave = {}
	local success,err = pcall(function()
		for i,v in pairs(folder:GetChildren()) do
			local valuetable = {}
			valuetable.Name = v.Name
			valuetable.Value = v.Value
			table.insert(toSave,valuetable)
		end
		ds:SetAsync(plr.UserId.."Values",toSave)
	end)
	if success then
		print("saved!")
	else
		print("something went wrong while saving")
		warn(err)
	end
end)

let me know if it worked

how do i make it work on the server, like not when a player has joined

just remove the player.added and player.removed and change it to whatever you want

local ds = game:GetService("DataStoreService"):GetDataStore("something13")

game.Players.PlayerAdded:Connect(function(plr)
	local folder = game.ReplicatedStorage.EconomyStuff.Cloud
	local values = ds:GetAsync("something13")
	for i,v in pairs(values) do
		for i,b in pairs(folder:GetChildren()) do
			if v.Name == b.Name then
				b.Value = v.Value
			end
		end
	end
end)

game:BindToClose(function()
	local folder = game.ReplicatedStorage.EconomyStuff.Cloud
	local toSave = {}
	local success,err = pcall(function()
		for i,v in pairs(folder:GetChildren()) do
			local valuetable = {}
			valuetable.Name = v.Name
			valuetable.Value = v.Value
			table.insert(toSave,valuetable)
		end
		ds:SetAsync("something13",toSave)
	end)
	if success then
		print("saved!")
	else
		print("something went wrong while saving")
		warn(err)
	end
end)

it prints saved but it doesnt save

try removing the player added function so it would look like this

local ds = game:GetService("DataStoreService"):GetDataStore("something13")


	local folder = game.ReplicatedStorage.EconomyStuff.Cloud
	local values = ds:GetAsync("something13")
	for i,v in pairs(values) do
		for i,b in pairs(folder:GetChildren()) do
			if v.Name == b.Name then
				b.Value = v.Value
			end
		end
	end


game:BindToClose(function()
	local folder = game.ReplicatedStorage.EconomyStuff.Cloud
	local toSave = {}
	local success,err = pcall(function()
		for i,v in pairs(folder:GetChildren()) do
			local valuetable = {}
			valuetable.Name = v.Name
			valuetable.Value = v.Value
			table.insert(toSave,valuetable)
		end
		ds:SetAsync("something13",toSave)
	end)
	if success then
		print("saved!")
	else
		print("something went wrong while saving")
		warn(err)
	end
end)
	

i thought i deleted that thanks