I am trying to make this GUI open when touching a brick/part and it seems not to work. Any help?
1 | script.Parent.Touched:connect( function () |
2 | game.StarterGui.Radio 1. Enabled = true |
3 | end ) |
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:
1 | local gui = script.YouGuiName |
2 | local brickTouchedEvent = game.ReplicatedStorage.YouRemoteEventNameHere |
3 |
4 | brickTouchedEvent.OnClientEvent:Connect( function () |
5 | gui.Enabled = true |
6 |
7 | end ) |
Then place a normal script inside your part to be touched and write this script:
01 | local brick = script.Parent |
02 | local brickTouchedEvent = game.ReplicatedStorage.YourRemoteEventNameHere |
03 | local debounce = false |
04 | brick.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 |
12 | end ) |
I hope this helps!
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:
1 | script.Parent.Touched:connect( function () |
2 | game.Players.LocalPlayer.PlayerGui.Radio 1. Enabled = true |
3 | end ) |
If it's a local script, it will work.
Hope this helped!
Before putting this in, make sure you put the GUI in ReplicatedStorage and the script is a LocalScript
1 | local RP = game:GetService( "ReplicatedStorage" ) |
2 | local gui = RP.Radio 1 |
3 |
4 | script.Parent.Touched:Connect( function () |
5 | gui.Parent = game.Players.LocalPlayer.PlayerGui |
6 | gui.Visible = true |
7 | end ) |
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