I would like to know how to make a datastore for a bool value, so it saves if the value is true or false
You would do the same as any other datastore but instead of the value being a number, it is a bool value instead!
3 Likes
Ya ik that but Im wondering how would I make it
2 Likes
DataSores can be strings / bools / numbers / tables
to save a bool values you can use this colde:
local DataStoreService = game:GetService("DataStoreService")
local BoolsData = DataStoreService:GetDataStore("Bools")
BoolsData:SetAsync("Key",true)
4 Likes
Pretty simple, I suggest watching over videos and the API of datastores.
--// SERVICES
local DataStoreService = game:GetService("DatastoreService")
--// VARS
local ds = DataStoreService:GetDataStore("datatest")
game.Players.PlayerAdded:Connect(function(plr)
local Folder = Instance.new("Folder",plr)
Folder.Name = "test"
local BoolValue = Instance.new("BoolValue",Folder)
BoolValue.Name = "BoolValue"
local dataofuser = ds:GetAsync(plr.UserId)
if dataofuser ~= nil then -- anything but nil
print("Found data for " .. plr.Name)
BoolValue.Value = ds[1]
else
print("Replacing no data with new data.")
BoolValue = false
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local datasave = {}
table.insert(datasave, plr:WaitForChild("test"):WaitForChild("BoolValue").Value)
local success,response = pcall(function()
ds:SetAsync(plr.UserId, datasave)
end)
if success then
print("succesfully saved data of " .. plr.Name)
else
warn(response)
end
end)
8 Likes
How do I save and load bool names with value?
thanks
cool i like it!, the thing is can it be on multiple boolean values, like lot?