I was just curious, is is possible to store a boolean value in a datastore (Like true, or false). I wanted to check to see if a player was new but I don't know if it would be possible to do this with true or false. Thanks, below is my current loading script (does use gui's) kinda random but just something to show you guys so I don't get in trouble for not showing current projects:
---------------------------------------------------------------------------------------------------- --Insert VARIABLES Below ---------------------------------------------------------------------------------------------------- local DataStore = game:GetService("DataStoreService"):GetDataStore("Money") local Player = script.Parent.Parent.Parent repeat wait() until game.Players[Player.Name].PlayerGui.MainScreen local info = script.Parent.Info local loadinginfo = script.Parent.LoadingScreen.LoadingInfo loadingstats = script.Parent.LoadingScreen.LoadingBar.LoadingStats local statsloaded = script.Parent.StatsLoaded ---------------------------------------------------------------------------------------------------- info.Visible = false if statsloaded.Value == false then statsloaded.Value = true repeat wait() until game.Players[Player.Name].PlayerGui.MainScreen loadinginfo.Text = "Loading Player Stats" local PlayerKey = "user_" .. Player.userId --// Never use the player's name as a key. loadingstats.Size = loadingstats.Size + UDim2.new(0.1,0,0,0) local money = game.Players[Player.Name].PlayerGui.MainScreen.Money loadingstats.Size = loadingstats.Size + UDim2.new(0.1,0,0,0) money.Value = DataStore:GetAsync(PlayerKey) --// Retrieving the value of the saved key. loadingstats.Size = loadingstats.Size + UDim2.new(0.1,0,0,0) wait(1) loadinginfo.Text = "Loading Images" loadingstats.Size = loadingstats.Size + UDim2.new(0.1,0,0,0) wait(1) loadingstats.Size = loadingstats.Size + UDim2.new(0.1,0,0,0) wait(1) loadingstats.Size = loadingstats.Size + UDim2.new(0.1,0,0,0) wait(1) loadingstats.Size = loadingstats.Size + UDim2.new(0.1,0,0,0) wait(1) loadinginfo.Text = "Finishing up" wait(1) loadingstats.Size = loadingstats.Size + UDim2.new(0.1,0,0,0) wait(1) loadingstats.Size = loadingstats.Size + UDim2.new(0.1,0,0,0) wait(1) loadingstats.Size = loadingstats.Size + UDim2.new(0.1,0,0,0) loadinginfo.Text = "Stats and images loaded" wait(2) script.Parent.LoadingScreen:Destroy() info.Visible = true elseif statsloaded.Value == true then info.Visible = true end
I haven't done it before, but I believe the answer is yes.
If not, there's a few facts that keep this convenient.
In the event that a key hasn't yet been made, GetAsync returns nil
.
nil
is falsey, so if you use it with if
, it will fail the condition just like false
; if you store any other value (except false) it will pass the condition.
if store:GetAsync("visited") then -- They visited before else -- Have not visited before end store:SetAsync("visited", true) -- If booleans for some reason don't work, instead use store:SetAsync("visited", "hasvisited") -- (Or any other value) -- (and the if remains the same)