How to convert this datastore into using true/false rather than numbers?

I have never worked with datastores before, so most of this data-saving code isn’t mine and I don’t know what I’m doing. I want to be able to make the data sent to the datastore to be the true or false values of game.Lighting.GlobalShadows instead of the number value of game.Lighting.ShadowSoftness.

--Server Script
local DataStoreService = game:GetService("DataStoreService")
local ShadowDataStore = DataStoreService:GetDataStore("ShadowDataSaving")
local Players = game:GetService("Players")
local Storage = game:GetService("ReplicatedStorage")
local SaveShadowsEvent = Storage.Events:WaitForChild("SaveShadows")
local shadow


SaveShadowsEvent.OnServerEvent:Connect(function(player, shadows)
	shadow = shadows
end)

Players.PlayerAdded:Connect(function(player)
	local key = "Shadow_"..player.UserId
	local res = ShadowDataStore:GetAsync(key)
	if type(res) == "number" then
		SaveShadowsEvent:FireClient(player, res)
	end
end)

Players.PlayerRemoving:Connect(function(player)
	if not shadow then
		return
	end
	local key = "Shadow_"..player.UserId
	local res = ShadowDataStore:SetAsync(key, shadow)
end)


SaveShadowsEvent.OnServerEvent:Connect(function(player, shadow)
	local key = "Shadow_"..player.UserId
	local res = ShadowDataStore:SetAsync(key, shadow)
end)

game:BindToClose(function()
	for _, player in pairs(Players:GetPlayers()) do
		if not shadow then
			return
		end
		local key = "Shadow_"..player.UserId
		local res = ShadowDataStore:SetAsync(key, shadow)
	end
end)
--Local Script
local Debounce = false
local Storage = game:GetService("ReplicatedStorage")
local SaveShadowsEvent = Storage.Events:WaitForChild("SaveShadows")
local Player = game.Players.LocalPlayer


script.Parent.MouseButton1Click:Connect(function()
	if Debounce then
		return
	end
	Debounce = true
		if game.Lighting.ShadowSoftness == 0 then 
		game.Lighting.ShadowSoftness = 1 -- makes shadows faded
		script.Parent.Text = 'Shadows Off'
		game.Lighting.GlobalShadows = false -- turns shadows off
		SaveShadowsEvent:FireServer(game.Lighting.ShadowSoftness) -- sends data to be saved
	elseif game.Lighting.ShadowSoftness == 1 then 
			game.Lighting.ShadowSoftness = 0 -- makes shadows sharper
			script.Parent.Text = 'Shadows On'
			game.Lighting.GlobalShadows = true -- turns shadows on
			SaveShadowsEvent:FireServer(game.Lighting.ShadowSoftness) -- sends data to be saved
		end
		task.wait(1)
		Debounce = false
end)

SaveShadowsEvent.OnClientEvent:Connect(function(shadow)
	if shadow == 1 then
		game.Lighting.GlobalShadows = false 
		game.Lighting.ShadowSoftness = 1 
		script.Parent.Text = 'Shadows Off'
	elseif shadow == 0 then
		game.Lighting.GlobalShadows = true 
		game.Lighting.ShadowSoftness = 0 
		script.Parent.Text = 'Shadows On'
	end
end)
1 Like

Roblox datastores store strings from my experience, not sure about booleans though.

1 Like

I did “some” research and I found that I could try connecting true/false values to numbers, but I’m not sure how I would go about doing this? Any help on that?

It would basically be the same as datastoring numbers (assuming storing booleans works the same as storing strings)