local player = game:GetService("Players").LocalPlayer
local de = false
script.Parent.MouseButton1Click:Connect(function()
if de == false then
de = true
for _, player in ipairs(game.Players:GetPlayers()) do
local char = player.Character
if char then
local hitbox = char:FindFirstChild("Hitbox")
if hitbox then
hitbox.Transparency = 0.5
else
print("found")
hitbox.Transparency = 1
de = false
end
end
end
end
end)
so this script works when i first click it but when i click it the second time it doesn’t turn back, the hitbox is still visible , i get no errors too.
If you’re going to post on here you should really explain what this is supposed to do in more detail so nobody has to read through your code fully to understand what you’re asking.
The reason the hitbox isn’t becoming visible a second time is because you are just checking if the hitbox exists, then and always setting its transparency to 0.5. You never check if the hitbox is already transparent. Also why is there a debounce in the script? There is no point other than it wasting space in your code.
You’re on the right track, but the behavior you’re seeing comes from how your toggle logic is structured. Once de is set to true, your button no longer responds to additional clicks because the condition if de == false then will never pass again.
Also, the else block where you try to reset transparency won’t run unless hitbox is missing — but you’re trying to toggle transparency on the same existing hitbox. Let me show you a cleaner way to structure this:
local player = game:GetService("Players").LocalPlayer
local toggle = false
script.Parent.MouseButton1Click:Connect(function()
toggle = not toggle
for _, player in ipairs(game.Players:GetPlayers()) do
local char = player.Character
if char then
local hitbox = char:FindFirstChild("Hitbox")
if hitbox then
hitbox.Transparency = toggle and 0.5 or 1
end
end
end)
Set de variable to false at the end of the if the == false then and delete your current de = false
like this:
if de == false then
de = true
for _, player in ipairs(game.Players:GetPlayers()) do
local char = player.Character
if char then
local hitbox = char:FindFirstChild("Hitbox")
if hitbox then
hitbox.Transparency = 0.5
else
print("found")
hitbox.Transparency = 1
end
end
end
de = false
end