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

How to make GUI appear with ClickDetector?

Asked by
Ap_inity 112
7 years ago
Edited 7 years ago

Here's an example ( http://i.gyazo.com/f15e9b3bcd70d6cea4d7121249b6133f.gif )

1 answer

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
7 years ago

You're going to have to do all the coding for the GUI itself. Here's a general idea of how the script was made.

ClickDetectors will automatically provide the player who clicked on the object. Regardless if the environment is FilteringEnabled or not. In this example, we can actually keep the script completely local. This will mean the MouseClick event will be processed by the client.

We're going to want to keep this local, so, we will need a LocalScript. LocalScripts will only work in the player's Character, PlayerScripts, PlayerGui, and Backpack. Since we're working with GUIs, I would recommend keeping the script in PlayerGui.

Since we're going to want to get access to the ClickDetector object, we want to make sure the part holding the ClickDetector has a unique name.

game.Workspace.PartWithAUniqueName.ClickDetector.MouseClick:Connect(function(Player)
    if Player == game.Players.LocalPlayer then --Since we are dealing with ClickDetectors, I am not sure, if in a Non-FilteringEnabled environment, if the clicking of an object is picked up by other clients. This just keeps the message from popping up for everyone.
        script.Parent.ScreenGui.Frame.Visible = true
    end
end)

What happens in the script is we access the part with a unique name to get the ClickDetector. We then tell the script to listen for the MouseClick event and run a function when the event is fired. The function is automatically provided the player argument. We then compare the Player argument we are provided to the LocalPlayer, that way the GUI shows for Player1 and Player1 only, not Player2 or Player3. For some reason Roblox Player and Studio are down for me, not sure if we should actually be checking this or if Roblox thought ahead. Once that we have confirmed it is the LocalPlayer clicking the ClickDetector, we set the GUI's frame to visible.


Once again, you are going to have to figure out the rest of the code on your own. We can not provide you with a full script. If this answered your question, do not forget to hit the accept answer button. If you have any questions, feel free to comment down below and I will get back to you.
Ad

Answer this question