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

How do I make a brick that opens up a gui once touched?

Asked by 7 years ago

I tried making a script that opened a gui once touched but it doesn't work? What did I do wrong?

function ontouched(part)
    script.Parent.Parent.Parent.StarterGui.ScreenGui.ImageLabel.Visible = true

script.Parent.Parent.Touched:connect(onTouch) 
end
1
This won't work in Server Mode if Filtering Enabled is set to true. You will need to use a RemoteEvent/Function to trigger the GUI opening and closing if FE is on. User#18718 0 — 7y
0
Read my bio. hiimgoodpack 2009 — 7y

2 answers

Log in to vote
0
Answered by
Bazuxk 95
7 years ago

The problem is because you typed the wrong function. Here I fix it for you:

-- in local script
function onTouch()
    script.Parent.Parent.Parent.StarterGui.ScreenGui.ImageLabel.Visible = true
    print('Touched!')
script.Parent.Parent.Touched:connect(onTouch) 

But, I recommend you write like this:

-- in local script
script.Parent.Parent.Touched:connect(function()
    script.Parent.Parent.Parent.StarterGui.ScreenGui.ImageLabel.Visible = true
    print('Touched!')
end)

Because the second one is easier to type.

0
You left out the second issue. Thundermaker300 554 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

You have a couple of problems:

  1. You are using StarterGui. You need to use PlayerGui on the person that pressed. Consider the example below.

  2. You are connecting the function inside it's self. Don't do that!

function ontouched(part)
local plr =game.Players:GetPlayerFromCharacter(part.Parent)
if plr then
plr.PlayerGui.ScreenGui.ImageLabel.Visible = true
end

end
script.Parent.Parent.Touched:Connect(ontouched) 
0
The script you provided doesn't work.. IAmSoloz 14 — 7y
0
Errors? Thundermaker300 554 — 7y
0
I'm not sure. IAmSoloz 14 — 7y

Answer this question