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

How do I save a BoolValue?

Here's my script: Script in ServerScriptService

local datastore = game:GetService("DataStoreService")
local MyMoney = datastore:GetDataStore("MoneyData")
local MyRuby = datastore:GetDataStore("RubyData")
local bsnss = datastore:GetDataStore("BusinessOwned")

game.Players.playerAdded:connect(function(player)
	local Money = Instance.new("IntValue", player)
	Money.Name = "Money"
	local Ruby = Instance.new("IntValue", player)
	Ruby.Name = "Rubys"
	local bsnes = Instance.new("Folder", player)
	bsnes.Name = "Businesses"
	local ps = Instance.new("BoolValue", bsnes)
	ps.Name = "Storage"
	ps.Value = false
	local aprt = Instance.new("BoolValue", bsnes)
	aprt.Name = "Apartment"
	aprt.Value = false
	
	Money.Value = MyMoney:GetAsync(player.UserId) or 1000 
	MyMoney:SetAsync(player.UserId, Money.Value) 
	Ruby.Value = MyRuby:GetAsync(player.UserId) or 10
	MyRuby:SetAsync(player.UserId, Ruby.Value)
	
	ps.Value = bsnes:GetAsync(player.UserId) or false
	bsnes:SetAsync(player.UserId, ps.Value)

game.Players.PlayerRemoving:connect(function()
	MyMoney:SetAsync(player.UserId, Money.Value) 
	MyRuby:SetAsync(player.UserId, Ruby.Value)
	end)
end)

1 answer

If a string value, bool value or any kind of value refuses to be saved inside of a store, then you can simply save them as an int value instead and call upon them via a table.

boolStates = {true, false}

print(boolStates[1]) -- prints true
print(boolStates[2]) -- prints false

--(Save 1 and 2 depending on true or false)

4 comments

0

So would I just need to add that into the beginning of my script?

0

Yeah. Then you treat 1 and 2 as true or false. This also works for strings, and since datastores don't support strings this is also the method I use.

0

Could you write or edit out the example for one of my bool values, I'm sorry this just isn

0

making sense to me

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