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

How to make a gui pop up when player CLICKS a block?

Asked by 4 years ago

Ive tried looking this up but everything i see is when a character STEPS on the brick, i just want the gui to pop up after the player clicks the block (in my case its a book).

2 answers

Log in to vote
0
Answered by
d1_rek 46
4 years ago

I'll just send you the script here, make sure to look into it because I made it for you for free.

local Click = script.Parent.Click

function Clicked()
    local plr = game.Players:FindFirstChild(game.Players.LocalPlayer.Name)
    plr.PlayerGui.ScreenGui.Frame.Visible = true
end

Click.MouseClick:connect(Clicked)

This should work, just make sure to reroute some variables so it works.

0
so how could i change which specific gui to open? mohawk2005ishacked12 13 — 4y
0
and it doesnt work, i get an error on line 4, something about the (.Name) mohawk2005ishacked12 13 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

To do this, you need to place a ClickDetector into the block itself. You can read more about those here.

Once that is added, you need to add a script under the ClickDetector that fires whenever it is activated through a mouse click. Below is the example used by Roblox.

local clickDetector = workspace.Part.ClickDetector

function onMouseClick()
    print("You clicked me!")
end

clickDetector.MouseClick:connect(onMouseClick)

Alternatively, you can replace the clickDetector variable to just have script.Parent. Either way, they can work but it gets kinda messy if you have multiple blocks with click detectors. That's why I'd use the script.Parent method.

If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.

Be sure to check out the Roblox API Documentation as well for additional reference.

0
so in the function mouse click instead of "print me" i can set the gui visibility to true? mohawk2005ishacked12 13 — 4y
0
Yes, you can insert whatever code you want to be ran. Here's a helpful tip, the `MouseClick` event has a parameter of the player that activated the click. So you can use `function onMouseClick(plr)` where `plr` would be referring to the Player that clicked the part. It makes life easy. TaxesArentAwesome 514 — 4y

Answer this question