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
4 years ago

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

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

3 answers

Log in to vote
2
Answered by 4 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:

local gui = script.YouGuiName
local brickTouchedEvent = game.ReplicatedStorage.YouRemoteEventNameHere

brickTouchedEvent.OnClientEvent:Connect(function()
gui.Enabled = true

end) 

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

local brick = script.Parent
local brickTouchedEvent = game.ReplicatedStorage.YourRemoteEventNameHere
local debounce = false
brick.Touched:Connect(function(hit)
    if not debounce then
        debounce = true
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        brickTouchedEvent:FireClient(player)
        wait(4)
        debounce = false
    end
end)

I hope this helps!

0
Beat me to it. Raccoonyz 1092 — 4y
0
Ty! imaA6D 39 — 4y
0
Both beat me to it. NarwhalAndMe 141 — 4y
0
np User#32819 0 — 4y
Ad
Log in to vote
1
Answered by
Raccoonyz 1092 Donator Moderation Voter
4 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:

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

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

Hope this helped!

0
mean User#32819 0 — 4y
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 — 4y
Log in to vote
1
Answered by 4 years ago

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

local RP = game:GetService("ReplicatedStorage")
local gui = RP.Radio1

script.Parent.Touched:Connect(function()
    gui.Parent = game.Players.LocalPlayer.PlayerGui
    gui.Visible = true
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

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 — 4y
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 — 4y

Answer this question