Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I save a BoolValue?

Asked by
Vxpper 101
5 years ago

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

Log in to vote
0
Answered by 5 years ago

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)
0
So would I just need to add that into the beginning of my script? Vxpper 101 — 5y
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. Pixeloite 0 — 5y
0
Could you write or edit out the example for one of my bool values, I'm sorry this just isn Vxpper 101 — 5y
0
making sense to me Vxpper 101 — 5y
Ad

Answer this question