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

How to make a GUI open upon touching a brick?

Asked by
imaA6D 39
5 years ago

I am trying to make this GUI open when touching a brick/part and it seems not to work. Any help?

1script.Parent.Touched:connect(function()
2    game.StarterGui.Radio1.Enabled = true
3end)

3 answers

Log in to vote
2
Answered by 5 years ago

It's because you're defining the gui on StarterGui, wich replicates it to the player in PlayerGui, so what you should do is create a localscript in the StarterGui and the GUI inside the localscript, a remote event inside replicatedstorage and write this script in the localscript:

1local gui = script.YouGuiName
2local brickTouchedEvent = game.ReplicatedStorage.YouRemoteEventNameHere
3 
4brickTouchedEvent.OnClientEvent:Connect(function()
5gui.Enabled = true
6 
7end)

Then place a normal script inside your part to be touched and write this script:

01local brick = script.Parent
02local brickTouchedEvent = game.ReplicatedStorage.YourRemoteEventNameHere
03local debounce = false
04brick.Touched:Connect(function(hit)
05    if not debounce then
06        debounce = true
07        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
08        brickTouchedEvent:FireClient(player)
09        wait(4)
10        debounce = false
11    end
12end)

I hope this helps!

0
Beat me to it. Raccoonyz 1092 — 5y
0
Ty! imaA6D 39 — 5y
0
Both beat me to it. NarwhalAndMe 141 — 5y
0
np User#32819 0 — 5y
Ad
Log in to vote
1
Answered by
Raccoonyz 1092 Donator Moderation Voter
5 years ago

Hello there! StarterGui is basically like StarterPack, except for GUIs. If you edit a GUI in StarterGui, it only will show up if a new player joins. To fix this, you can do the following:

1script.Parent.Touched:connect(function()
2    game.Players.LocalPlayer.PlayerGui.Radio1.Enabled = true
3end)

If it's a local script, it will work.

Hope this helped!

0
mean User#32819 0 — 5y
0
Just because someone else answered after you doesn't mean they copied you or stole from you, they could have just posted the post and your answer wasn't there intill he clicked answer (by refreshing the answers). moo1210 587 — 5y
Log in to vote
1
Answered by 5 years ago

Before putting this in, make sure you put the GUI in ReplicatedStorage and the script is a LocalScript

1local RP = game:GetService("ReplicatedStorage")
2local gui = RP.Radio1
3 
4script.Parent.Touched:Connect(function()
5    gui.Parent = game.Players.LocalPlayer.PlayerGui
6    gui.Visible = true
7end)

Comment on this answer if it doesn't work, and if you want anything else implemented into this script (if you walk off the brick it gets rid of the GUI, the GUI fade-in, etc.)

Your welcome if it worked,

Narwhal

0
This is unnessary, you could just change the enabled value (if it was a gui) or visible (if it was a frame). moo1210 587 — 5y
0
Im sorry I didn't know it was in the starter gui. Plus, this is the way I do it. Also, I forgot it was Enabled for a gui. In my early days of developing, I was making a model greatly depending on guis. I didn't understand the gui's properties, so in the script I made the gui Enabled and tried to make it visible using the Visible property even though there's no such thing. That threw me off. NarwhalAndMe 141 — 5y

Answer this question