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

I am trying to make a GUI pop-up when I touch a brick but it wont work, why?

Asked by 5 years ago

I may be dumb but I can`t make it work.. I tried finding a way to do it but it failed and gave me an error (StarterGui is not a member of PlayerGui or something..)

I made this, I know it wont work but I am actually tired.. I have no idea what code should I use to make it work. I know how to read a code but no matter what code I use: It. Never. Works.

local GuiOpener = script.Parent --The part that supposed to open the GUI for me when I touch it
local Gui = game.StarterGui.AreYouSure --The GUI that wont show up


script.Parent.Touched:connect(function()
    Gui.TextButton.Visible = true --I have no idea how to use the PlayerGui.
end)

Any help please? I really want to develop my game but this one thing wont let me.. :\

0
Is this a global or local script? Global Scripts cannot access the PlayerGui, but the Touched event is a global function if I am not mistaken. Despayr 505 — 5y
0
You are referencing the StarterGui, when you should be referencing the PlayerGui Despayr 505 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

Hello there! Since you are referring to startergui, it does not work. All GUI's get cloned from StartedGui to the PlayerGui. The problem is, that "PlayerGui" is located client-sided. Therefore, we must use a remote event.

There are 2 scripts. This has to be in the part itself:

-- Name: "Script"
local GuiOpener = script.Parent --The part that supposed to open the GUI for me when I touch it
local event = Instance.new("RemoteEvent",game.ReplicatedStorage)
event.Name = "OpenAreYouSureGui"

GuiOpener.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then   
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        event:FireClient(player)
    end
end)

And this screen has to be in the screengui:

-- Name: "LocalScript"
local event = game.ReplicatedStorage:WaitForChild("OpenAreYouSureGui")

event.OnClientEvent:Connect(function()
    script.Parent.TextButton.Visible = true
end)

Don't know where to put them?

https://gyazo.com/649cfcd61767b88e4931b205aaaac047

0
I'm so confused. But it worked, thanks man. I will try to understand the code right now lol HeyItzDanniee 252 — 5y
0
You're welcome! If you got any more questions, let us know! :) marketmanager1 52 — 5y
Ad
Log in to vote
0
Answered by
Aimarekin 345 Moderation Voter
5 years ago

You are referencing the StarterGui. Reference the PlayerGui instead.

local GuiOpener = script.Parent --The part that supposed to open the GUI for me when I touch it
local Gui = game.Players.LocalPlayer.PlayerGui.AreYouSure


script.Parent.Touched:connect(function()
    Gui.TextButton.Visible = true
end)

0
Doesn`t works HeyItzDanniee 252 — 5y
0
^Yep. This is because you are still working using a localplayer, in a server sided script. Also, since we use filtering enabled, this wouldn't even work with the right path for the gui. Use remote evens, as explained in the answer down below. :) marketmanager1 52 — 5y
0
He never said this was a server script so by default I thought it was a localscript. Aimarekin 345 — 5y
0
And I already knew that, marketmanager1 Aimarekin 345 — 5y

Answer this question