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

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

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

2 comments

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.

0

Read my bio.

2 answers

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.

1 comment

0

You left out the second issue.

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) 

3 comments

0

The script you provided doesn't work..

0

Errors?

0

I'm not sure.

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