Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make the text buttons disappear when when the mouse button clicks?

Asked by 7 years ago

I am currently making a GUI for an upcoming game that I am making for Roblox. However, I am having difficulties making the Text, and Image buttons disappear when any of the Main Children are being clicked. The script was a load out GUI that I modified to fulfill my style of the game. So I can Understand That I may be difficult, and reside to other possibilities. Here is a sample of the script that I tried to modify: (more info at the bottom)

--{ Variables/Assignments }-- player = script.Parent.Parent.Parent backpack = player.Backpack

--{ Functions }-- function chooseClass(class) for i, v in pairs(backpack:GetChildren()) do v:remove() end for i, v in pairs(class:GetChildren()) do if v:IsA("Tool") then v:clone().Parent = backpack elseif v:IsA("HopperBin") then v:clone().Parent = backpack end

01end
02 
03 
04 
05script.Parent.Main.Visible = false
06script.Parent.Title.Visible = false
07script.Parent.Assault.Visable = false
08script.Parent.Medic.Visable = false
09script.Parent.Recon.Visable = false
10script.Parent.Support.Visable = false
11script.Parent.Shop.Visable = false
12script.Parent.Money.Visable = false

end

function onHumanoidDied(humanoid, player) script.Parent.Main.Visible = true script.Parent.Title.Visible = true script.Parent.Assault.Visable = true script.Parent.Medic.Visable = true script.Parent.Support.Visable = true script.Parent.Recon.Visable = true script.Parent.Shop.Visable = true script.Parent.Money.Visable = true end

for i, v in pairs(script.Parent.Main:GetChildren()) do v.MouseButton1Up:connect(function () chooseClass(v) end)

end

To put you In perspective there is a GUI labeled "StarterGUI" and Its Children Are The "Main". The main consists of 4 children being all text Buttons. "Support", "Recon", "Medic" and "Assault". Next there is an ImageButton Titled "Money". Next there are also 4 other buttons that contain many tween scripts (not important). The 5 buttons are also named "Shop", "Gadgets", "Assault", "Recon", "Support" and "Medic". Please respond soon!

1-Shiftmaster27
0
RIP CODE greatneil80 2647 — 7y
0
dude use code blocks TheSkyofIndia 150 — 7y

2 answers

Log in to vote
0
Answered by
y3_th 176
7 years ago

All you have to do is make a .MouseButton1Click event connect to a function that deletes all text/image buttons. Although, it's preferred to delete the frame containing these buttons.

Examples:

1--destroying one button
2 
3local Foo = script.Parent
4 
5Foo.MouseButton1Click:Connect(function() --script is child of foo the button
6    Foo:Destroy()
7end)
01--destroying all text and image buttons
02 
03local Foo = script.Parent
04local FooFrame = Foo.Parent --assuming that Foo is child of FooFrame
05 
06--instead of a for loop going through all buttons, we just delete the frame for all buttons
07Foo.MouseButton1Click:Connect(function()
08    FooFrame:Destroy()
09end)
10 
11--the gui will still pop up in PlayerGui after being destroyed
Ad
Log in to vote
0
Answered by 7 years ago
01local GUI = --Whereever your GUI is located--
02 
03Detector = --Whereever your detector is but its easier for me to just type where it is in the bottom--
04--Lets say the detector is in script.parent.parent.Delete.ClickDetector--
05 
06-- If you want to destroy the GUI (It cant be brought back unless cloned)--
07function Delete()
08    GUI:Destroy()
09end
10--On the bottom if you just a want it to not be visible but you can always make it visible again--
11 
12function Invisible()
13    GUI.Visible = false
14end
15 
16 
17script.parent.parent.Delete.ClickDetector.MouseButton1Click:Connect(--Put Delete if you want it deleted or Invisible if you just dont want it Visible--)

If the game is Filtering enabled and you want to for some reason make it where everyone sees the GUI destroyed then you should use remoteevent/remotefunctions. Otherwise you should be good learning off this.

Answer this question