BoolValue DataStore Failing

Hello all, having troubles!
This is my script(Saving Boolean Values, or, with some editing of the source, any type of value inside the table)

I’d like to know as to why this USED to work, but now doesn’t? I’ve tried to change the name, and it didn’t work, I’ve also done a lot of different edits to the script, but I am open to every idea you guys may or may not have as to why this isn’t working.
Thanks for reading my post and giving feedback!

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local BoolTestDataStore = DataStoreService:GetDataStore("PlayerSaveData")

local data = {
	--// Tools \\--
	["Bloxxer"] = false,
	["AngelicCrescent"] = false,
	["RustedMaul"] = false,
	["ConcreteMaul"] = false,
	["DemonicCrescent"] = false,
	["DragonFury"] = false,
	["Equalizer"] = false,
	["Slicer"] = false,
	
	
	
	--// Chars \\--
	["Jake"] = true,
	["Poleski"] = false,
	["Ivan"] = false,
	["DeRetto"] = false,
	["Bianca"] = false,
	["Serge"] = false,
	["Hektor"] = false,
	["Akas"] = false,
	["Bane"] = false,
	["Splinter"] = false,
	["Ragnoroc"] = false,
		
}

Players.PlayerAdded:Connect(function(Player)
	local BoolDataStore = nil
	
	local bools = Instance.new("Folder")
	bools.Name = "Bools"
	bools.Parent = Player
	
	for name, value in pairs(data) do
		local new = Instance.new("BoolValue")
		new.Name = name
		new.Value = value
		new.Parent = bools
	end
	
	local s, e = pcall(function()
		BoolDataStore = BoolTestDataStore:GetAsync("uid-" .. Player.UserId)
	end)
	
	if s then
		print("Getting Bool Data For: " .. Player.Name)
		if BoolDataStore then
			for name, value in pairs(BoolDataStore) do
				Player.Bools[name].Value = value
			end
			print("Bool Data Loaded For: " .. Player.Name)
		else
			print("Created New Bool Data For: " .. Player.Name)
		end
	else 
		warn("Error Getting Bool Data For: " .. Player.Name)
	end
end)

Players.PlayerRemoving:Connect(function(Player)
	print("Bools")
	local BoolDataStore = {}
	
	for name, value in pairs(Player.Bools:GetChildren()) do
		BoolDataStore[value.Name] = value.Value
	end
	
	local success = pcall(function()
		BoolTestDataStore:SetAsync("uid-"..Player.UserId, BoolDataStore)
	end)
	
	if success then
		print("Successfully Saved Bool Data For: " .. Player.Name)
	else
			print("FailedBool")
	end
end)
1 Like

Saving dictionaries do not work if your saving it by datastore.
you should:

local httpservice = game:GetService("HttpService")
local data = {
	--// Tools \\--
	["Bloxxer"] = false,
	["AngelicCrescent"] = false,
	["RustedMaul"] = false,
	["ConcreteMaul"] = false,
	["DemonicCrescent"] = false,
	["DragonFury"] = false,
	["Equalizer"] = false,
	["Slicer"] = false,
	
	
	
	--// Chars \\--
	["Jake"] = true,
	["Poleski"] = false,
	["Ivan"] = false,
	["DeRetto"] = false,
	["Bianca"] = false,
	["Serge"] = false,
	["Hektor"] = false,
	["Akas"] = false,
	["Bane"] = false,
	["Splinter"] = false,
	["Ragnoroc"] = false,
		
}
local thing = httpservice:JSONEncode(data) -- Transforms the dictionary into a string.
datastore:SetAsync('uid-'..Player.UserId, thing)
-- if you want to recieve it:
local bing = httpservice:JSONDecode(datastore:GetAsync('uid-'..Player.UserId)) -- turns it back into a dictionary
1 Like

Saving dictionaries as JSON isn’t needed via JSONEncode. SetAsync can automatically convert dictionaries to JSON.

2 Likes

When I tried it, it did not work.
Also it only works if your doing it like this:

DS:SetAsync("key", {
 coins = 100,
 gems = 5,
 level = 3,
 xp = 758
})

instead of defining it first in your script.

1 Like

Thanks for this information, considering I am fairly new to this DataStore with Tables/Dictionaries, I am wondering, would I simply place this on top of my code, or just replace the lines which were previously referring to DataStore system? Or am I confused.

What exactly doesn’t work in your code? You mentioned several times that you’re experiencing troubles with your script and that it doesn’t work, but you don’t ever specify what about it doesn’t work. Care to explain what’s failing here? That’s information that should be provided from the start rather than leaving us to investigate so we can help out at all, provided a quick skim doesn’t do the trick.

2 Likes

Passing in a previously defined table is the exact same as making the table from within the SetAsync call.

1 Like

Apologies, as I’m not exactly sure what doesn’t work. My guess is on PlayerRemoving, as I’ve been adding prints throughout the store system, and they prints fire, until player removing where the success print doesn’t fire.

You’re going to need to get a whole lot more specific than that or identify where the exact problem is, whether it’s an event not running (or being blocked), DataStores are empty, malformed collection in PlayerRemoving, whatever. If your script doesn’t work, then there’s a certain point where it’s going wrong and that needs to be identified.

1 Like

They’re empty, not saving on PlayerRemoving.