Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Boolean value coming as false, not as true, why? Datastores

Hello! I have wrote a boolean datastore and I am running into a problem.

Setting the value to "true" for the character Alice isn't happening, and it's being set to false. I noticed studio updated, and decided to make us have to commit scripts which is beyond annoying, and will probably end up changing back to normal in the foreseeable future, BUT, the problem still lies there for now as to why this doesn't function.

I made a server script to try to set the value to true when player added, and the DataStore overrides it, because of the "Playeradded" function, and the saving.

Here is my script, any and all help for this would be appreciated!!

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

local data = {
	--// Tools \\--
	["Bloxxer"] = false,
	["AngelicCrescent"] = false,
	["RustedMaul"] = false,
	["ConcreteMaul"] = false,
	["DemonicCrescent"] = false,
	["DragonFury"] = false,
	["Equalizer"] = false,
	["Slicer"] = false,
	
	
	
	--// Chars \\--
	["Alice"] = true,	
}

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)
	local BoolDataStore = {}
	
	for name, value in pairs(Player.Bools:GetChildren()) do
		BoolDataStore[value.Name] = value.Value
	end
	
	local success = pcall(BoolTestDataStore.SetAsync, BoolTestDataStore, "uid-" .. Player.UserId, BoolDataStore)
	
	if success then
		print("Successfully Saved Bool Data For: " .. Player.Name)
	end
end)

1 comment

0

Can you save tables without using JSONEncode and JSONDecode???

1 answer

✓ Accepted answer

Because there is no method such as .SetAsync the method you're looking for is :SetAsync That is what lines 62-63 supposed to be instead.

local success, errorMsg = pcall(function()
	BoolTestDataStore:SetAsync("uid-" .. Player.UserId, BoolDataStore)
end)

4 comments

0

That breaks the script.

0

That breaks the script.

0

You probably wrote it wrong then, i updated my answer to show you how you're supposed to have it

0

I had to edit my script some, but this functioned properly, thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.