Problem Datastore

I have a problem with this datastore it takes the same thing every time say it’s a BoolValue and when I leave it stores them both as true…

local m = require(script.Parent.Instellingen)
local DSS = game:GetService("DataStoreService"):GetDataStore("CarDealerSpijkenisse")

game.Players.PlayerAdded:Connect(function(plr)
	if DSS:GetAsync(plr.UserId.."-AUTODATA") ~= nil then
		local F = Instance.new("Folder", plr)
		F.Name = "AutoStats"

		for i, v in pairs(m.Autos) do
			local C = script.Parent.Example:Clone()
			C.Parent = F
			C.Name = v.Naam
			C.Value = DSS:GetAsync(plr.UserId.."-AUTODATA")
		end
	else
		local F = Instance.new("Folder", plr)
		F.Name = "AutoStats"

		for i, v in pairs(m.Autos) do
			local C = script.Parent.Example:Clone()
			C.Parent = F
			C.Name = v.Naam
			C.Value = false
		end
	end
end)
game.Players.PlayerRemoving:Connect(function(plr)
	local Save = {}
	for i, v in pairs(plr.AutoStats:GetChildren()) do
		Save[v] = v.Value
		DSS:SetAsync(plr.UserId.."-AUTODATA", Save)
	end
end)

I’m not entirely sure why both of the stores would be set as true, but I can spot a few issues with the datastore that may be causing problems. The biggest thing you have to do is move the DSS:SetAsync(plr.UserId.."-AUTODATA", Save) outside of the for loop. Every single time it’s reading all the stats and only writing the most recent stat, erasing everything else.

Another issue is you use GetAsync twice in the PlayerAdded, when it’d probably be better to create a variable with the response, and only call it once so you’re not using up the queue.

The one for i, v in pairs is for the values ​​that need to be saved. So then saving won’t work anyway.

Yes it needs to save all the values however the implementation you posted rewrites the datastore with only the most recent value so you’ll only ever store one value.

i have fixed it, thanks for helping.

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