DataStore script for storing alot of values

i need a script that can save all the color values , bool values , string values and int values under the
player in a folder.Can anyone help me with this? if you wanna chat on discord : Smitzy#0986 for more info.

You could put all of the information into a dictionary (Tables) then save that to datastoreservices. if that doesn’t work, you can try using HTTPService:JSONEncode() and HTTPService:JSONDecode() to store the info from the table in a string to save it

it has multiple values with the same name. So i think when i tried to save it thru datastore it doesnt work.

You may have to change it so they all have unique names then

hmm i think i will try to make different names and then save it thru datastore. if it doesnt work then il let you know.

game.Players.PlayerAdded:Connect(function(player)
	local folder = player:WaitForChild("CivCars")
	local MyDataStore = game:GetService("DataStoreService"):GetDataStore("ValuesSave")
	local success,data = pcall(function()
		return MyDataStore:GetAsync(player.UserId)
	end)
	print(data)
	if not data then
		print("No data found")
	end
	for i, v in pairs(data) do
		for i,ve in pairs(folder:GetDescendants()) do
		ve:WaitForChild(i).Value = v
	end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
	local MyDataStore = game:GetService("DataStoreService"):GetDataStore("ValuesSave")
	local folder = player:WaitForChild("CivCars")
	local dictionary = {}
	for i,v in pairs(folder:GetDescendants()) do
		if v:IsA("BoolValue") or v:IsA("IntValue") or v:IsA("StringValue") then
			print(v.Name)
			dictionary[v.Name] = v.Value
		end
	end
	local success = pcall(function()
		MyDataStore:SetAsync(player.UserId, dictionary)
	end)
end) ```
this what iv got but its not working
local players = game:GetService("Players")
local datastores = game:GetService("DataStoreService")
local datastore = datastores:GetDataStore("DataStore")

players.PlayerAdded:Connect(function(player)
	local folder = player:WaitForChild("CivCars")

	local success, result = pcall(function()
		return datastore:GetAsync(player.UserId)
	end)

	if success then
		if result then
			if type(result) == "table" then
				for name, value in pairs(result) do
					local object = folder:FindFirstChild(name, true)
					if object then
						object.Value = value
					end
				end
			end
		end
	else
		warn(result)
	end
end)

players.PlayerRemoving:Connect(function(player)
	local folder = player:WaitForChild("CivCars")

	local data = {}

	for _, child in ipairs(folder:GetDescendants()) do
		if child:IsA("ValueBase") then
			data[child.Name] = child.Value
		end
	end

	local success, result = pcall(function()
		return datastore:SetAsync(player.UserId, data)
	end)

	if success then
		if result then
			print(result)
		end
	else
		warn(result)
	end
end)

game:BindToClose(function()
	for _, player in ipairs(players:GetPlayers()) do
		local folder = player:WaitForChild("CivCars")

		local data = {}

		for _, child in ipairs(folder:GetDescendants()) do
			if child:IsA("ValueBase") then
				data[child.Name] = child.Value
			end
		end

		local success, result = pcall(function()
			return datastore:SetAsync(player.UserId, data)
		end)

		if success then
			if result then
				print(result)
			end
		else
			warn(result)
		end
	end
end)

This script worked for me (I created the required folder named “CivCars” and a random StringValue instance which stored my username).

Hey forrumer. I have tried this script and it doesnt save.
Heres the error im getting:
DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = VehiclesData

I have noticed im getting the same error as the colorsave script you showed me as an example.

Means you’re joining/exiting the game too frequently, each DataStore key gets around 10 requests to that particular DataStore per minute.

The game performs 2 DataStore requests total for each player (3 if you’re testing in studio), 1 when the player joins and 1 more when the player leaves.

I did test the script personally and it worked fine on my end.

Did you test the script in studio or in game? I waited a solid minute before leaving and rejoining.It didnot save and i got the same error.

Also this is what i get as the result is printed @Forummer
08D9E98D7B6369CB.0000000006.08D9E98F8E80D167.01

Yeah, that means the DataStore request was successful.

It’s not an error, it’s a warning, the DataStore request is queued and will still go through.

If i go back then why are the values not saved for example i had the value as true but when i came back it became false @Forummer

Because values which are set from the client do not replicate to the server.

I set the values from a server script. Not a local script.

Here’s a random script I’m using to test.

image

This is before I’ve left the game.

image

Now the random value has been removed.

image

This is when I’ve rejoined the game.

image

As you can see the value has been saved and loaded correctly.

It’s vital that you give each value instance a unique name.

Thanks for helping me for the past few days. I will try my best to fix these issues by myself. Im pretty sure your script works and that it is gotta be something on my end.