How would I save BoolValues?

Hello!

I am trying to make a data store which saves Bool Values, but I’m unsure how to. The way the system works is, a BoolValue is created, and inserted into a “Values” folder, by a local script once the player clicks a purchase button. This value is set to false, but when moved to the folder it’s set to true.

Does anyone know how to save the values which have been inserted, and how to make sure it saves their values?

Thanks!

Do you want it to like save and when the player leaves and joins back it loads the bool?

1 Like

No. Datastores can save bool values. I think.

1 Like

My bad, it’s 1 am here so my head isn’t working correctly lol.

In that case you should just be able to pass the value alongside a remote event with a request to save the value

1 Like

DataStoreService documentation: here
Uhh script I guess?

local DataStoreService = game:GetService("DataStoreService")

local DataStore = DataStoreService:GetDataStore("PlayerData")

game:GetService("Players").PlayerAdded:Connect(function(plr)
	local Data = DataStore:GetAsync(plr.UserId)
	
	local Folder = Instance.new("Folder",plr)
	Folder.Name = "Values"
	
	local b = Instance.new("BoolValue",Folder)
	b.Name = "Bool"
	
	if Data then
		print(Data)
	end
end)

game:GetService("Players").PlayerRemoving:Connect(function(plr)
	DataStore:SetAsync(plr.UserId,plr:WaitForChild("Values"):WaitForChild("Bool",math.huge).Value)
end)
1 Like

Yes but OP specified that the value is added through a local script, which means in order to save it they’ll need to call SetAsync() from the server, which they can request with a remote event.

1 Like

Yeah, how important is the bool value?

Yes. It’s used in a “Buy Item” system where the player buys an Item by clicking the button, and the button has a script in it where it creates the bool value, sets the value to false, and it has a designated name for the value. Then, the value is put inside the “Values” folder where it’s then changed to true and then the folder saves the value.

It’s used so the purchase button can disappear once the value is true and is in the value save folder. So in this system, it’s kind of important.

1 Like

You want it to save when the value is changed from false to true or from true to false?

I want it to save from when the value is false to true.

You can do:

Bool:GetPropertyChangedSignal("Value"):Connect(function()
   -- code
end)

When creating the bool value. (To like run the code that saves)

1 Like

Okay, will give it a try thanks!