How can I make the keybind make it transparent after tapping it again?

Hello, so I put together a simple script to make headphones visible when you press the keybind Z. But how can I make it so that once you tap it again, it will make the headphones transparent again?

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local headphones = char:WaitForChild("Headphones")

UIS.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	if Input.KeyCode == Enum.KeyCode.Z then
		headphones.Transparency = 0
	end
end)
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local headphones = char:WaitForChild("Headphones")

UIS.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	if Input.KeyCode == Enum.KeyCode.Z then
		if headphones.Transparency == 1 then 
			headphones.Transparency = 0 
		else 
			headphones.Transparency = 1
		end
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.