Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can i show a gui when a button si clicked ?

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

1 comment

0

be sure to accept my answer if it helped

1 answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.