This SurfaceGui makes a part when clicked. How do I make the part disappear when I click the Surface Gui again?
local Surface = Instance.new("SurfaceGui", script.Parent) Surface.Adornee = script.Parent local frame = Instance.new("Frame", Surface) frame.Size = UDim2.new(.8, 160, 1, 160) frame.Transparency = 1 local Button = Instance.new("TextButton",frame) Button.Size = UDim2.new(.8, 160, 0.58, 160) Button.BackgroundColor3 = BrickColor.White().Color Button.Text = "Brick Creator" Button.TextScaled = true Button.MouseButton1Down:connect(function() local brick Instance.new("Part", game.Workspace) end)
Try this. When ClickSwitcher = false, the part will be created upon clicking. When it = true, The part specified within the parenthesis will be destroyed.
ClickSwitcher = false -- Acts as a sort of Debounce. Button.MouseButton1Down:connect(function() if ClickSwitcher = false then ClickSwitcher = true local brick Instance.new("Part", game.Workspace) brick.Name = ("DeletionTarget") elseif ClickSwitcher == true then ClickSwitcher = false local brick2 = game.Workspace:FindFirstChild("DeletionTarget") brick2:Destroy()
Let me know if this helps!