How to adjust player visibility in a multiplayer game?

I use this so that when a player dies, they are reset with a transparency of 0.4 for the other players.

for _, otherPlayer in ipairs(Players:GetPlayers()) do
				if otherPlayer ~= player then
					ToggleTransparencyEvent:FireClient(otherPlayer, player, 0.4)
				end
			end

But in settings, I have an option that completely hides the other players, the code works, but when they die, they always reappear with 0.4 instead of 1 if the view option is OFF.

-- See Square of other Players
local stateButton = script.Parent:WaitForChild("StateFrame"):WaitForChild("State")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ToggleTransparencyEvent = ReplicatedStorage:WaitForChild("ToggleTransparencyEvent")

local isTransparent = true -- Comienza con los jugadores visibles

local function toggleTransparency(isTransparent)
	ToggleTransparencyEvent:FireServer(isTransparent and 0.4 or 1)
end

local function updateButtonState()
	local newPosition
	if isTransparent then
		-- Mueve el botón a la posición "ON" (derecha) y cambia el texto a ON
		newPosition = UDim2.new(1, -stateButton.Size.X.Offset, 0.5, -stateButton.Size.Y.Offset / 2)
		stateButton.Text = "ON"
	else
		-- Mueve el botón a la posición "OFF" (izquierda) y cambia el texto a OFF
		newPosition = UDim2.new(0, 0, 0.5, -stateButton.Size.Y.Offset / 2)
		stateButton.Text = "OFF"
	end
	stateButton.Position = newPosition
end

local function toggleState()
	isTransparent = not isTransparent
	updateButtonState()
	toggleTransparency(isTransparent)
end

stateButton.MouseButton1Click:Connect(toggleState)

updateButtonState()
toggleTransparency(isTransparent)

Then, to add more context, these two codes handle the events:
OtherPlayers in StarterPlayerScripts:

-- Access to the necessary services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- References to the RemoteEvents
local NotifyPlayersEvent = ReplicatedStorage:WaitForChild("NotifyPlayersEvent")
local ToggleTransparencyEvent = ReplicatedStorage:WaitForChild("ToggleTransparencyEvent")

-- Function to adjust the appearance of a specific player
local function adjustAppearance(targetPlayer)
	repeat wait() until targetPlayer.Character and targetPlayer.Character:FindFirstChild("Square")
	local character = targetPlayer.Character
	local square = character:FindFirstChild("Square")

	if square then
		square.Transparency = 0.4
		for _, child in ipairs(square:GetChildren()) do
			if child:IsA("Decal") then
				child.Transparency = 0.4
			end
		end
		for _, child in ipairs(character:GetChildren()) do
			if child:IsA("Decal") then
				child.Transparency = 0.4
			end
		end
	end
end

-- Function to change the transparency of a specific player
local function toggleTransparency(targetPlayer, transparencyValue)
	repeat wait() until targetPlayer.Character and targetPlayer.Character:FindFirstChild("Square")
	local character = targetPlayer.Character
	local square = character:FindFirstChild("Square")

	if square then
		square.Transparency = transparencyValue
		for _, child in ipairs(square:GetChildren()) do
			if child:IsA("Decal") then
				child.Transparency = transparencyValue
			end
		end
		for _, child in ipairs(character:GetChildren()) do
			if child:IsA("Decal") then
				child.Transparency = transparencyValue
			end
		end
	end
end

-- Event that is triggered when the local player joins or respawns
Players.LocalPlayer.CharacterAdded:Connect(function()
	NotifyPlayersEvent:FireServer(Players.LocalPlayer)
end)

-- Listen to server notifications on how to visualize other players
NotifyPlayersEvent.OnClientEvent:Connect(adjustAppearance)
ToggleTransparencyEvent.OnClientEvent:Connect(toggleTransparency)

PlayerHandler in ServerScriptService:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local NotifyPlayersEvent = ReplicatedStorage:WaitForChild("NotifyPlayersEvent")
local ToggleTransparencyEvent = ReplicatedStorage:WaitForChild("ToggleTransparencyEvent")

NotifyPlayersEvent.OnServerEvent:Connect(function(playerToExclude)
	for _, player in ipairs(Players:GetPlayers()) do
		if player ~= playerToExclude then
			NotifyPlayersEvent:FireClient(player, playerToExclude)
		end
	end
end)

ToggleTransparencyEvent.OnServerEvent:Connect(function(player, transparencyValue)
	for _, otherPlayer in ipairs(Players:GetPlayers()) do
		if otherPlayer ~= player then
			ToggleTransparencyEvent:FireClient(player, otherPlayer, transparencyValue)
		end
	end
end)