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

Can i show a gui when a button si clicked ?

Asked by 5 years ago

So i want to create a button , so a part with a button that when u press it a gui appear for the person who cliked on the button ...

I dont know how to do that so if u knwow answer me thx :p

0
be sure to accept my answer if it helped theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

There are two ways of detecting GUI clicks , those use MouseButton1Click and Activated, which is preferred.


Activated Event


The activated event is an event of image/text buttons that fires which a gui is clicked by the lmb and has a input object parameter.

local button = script.Parent

button.Activated:Connect(function(io)
    print("clicked")
end)

Other things


However, if you are using another mouse button such as the middle mouse button or the right mouse button, you would have to use MouseButton2Click and MouseButton3Click for rmb and mmb respectively.

local button = script.Parent

button.MouseButton2Clicked:Connect(function()
    print("clicked by rmb")
end)

button.MouseButton3Clicked:Connect(function()
    print("clicked by mmb")
end)

Click Detectors


However, if you don't want to have a gui button, you could just put a click detector in a part that you want to act as a button.

The click detector object has a MouseClick function with a playerWhoClicked parameter, so you can easily tell who clicked it.

local cd = script.Parent.ClickDetector

cs.MouseClick:Connect(function(plr)
    print(plr.Name.." clicked the button")
end)

references


Activated event

Input Object

MouseClick function

Hopefully this helped, be sure to accept if it did!

Ad

Answer this question