How to make a key unequip after equipping?

Hello!
I’ve been making a script, (Keep in mind, theres no bugs with the actual script.)
and I’m making it so when you press a certain button, it fires a server that makes an accessories handle transparent / visible.
Heres my script.

local PlayerWithSword = {"name", "name"}
local player = game.Players.LocalPlayer

repeat wait() until player.Character.Humanoid

local ShowKatanaEvent = game.ReplicatedStorage:WaitForChild("ShowKatana")

local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()
local character = player.Character

Cooldown = false

mouse.KeyDown:connect(function(key)
	if key == "h" then
		if not Cooldown then
			Cooldown = true
			ShowKatanaEvent:FireServer()
			wait(0.1)
			Cooldown = false
		end
	end
end)

Now, I was wondering how I could make it so when the key “h” is pressed a second time, it “unequips” (making it transparent) the handle.

What I want is for when H is pressed the first time, it makes the handle visible. If it’s pressed a second time, it makes the handle invisible, and so on…

Any help is appreciated!

You could check the handle’s current transparency and toggle it

ShowKatanaEvent.OnServerEvent:Connect(function(player)

   local EquippedTool = player.Character:FindFirstChildWhichIsA("Tool")

   if EquippedTool.Handle.Transparency == 0 then
         EquippedTool.Handle.Transparency = 1
   else
         EquippedTool.Handle.Transparency = 0
   end

end)

I’ll try this. It might take a while since I’m doing something else right now. Thanks for the reply, though!

1 Like

It worked, thank you so much!! (this also made another issue, but ill just ask devforum again. I am that desperate. But besides it constantly equipping and unequipping, it works!

1 Like

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