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

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

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.. :\

2 comments

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.

0

You are referencing the StarterGui, when you should be referencing the PlayerGui

2 answers

✓ Accepted answer

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

2 comments

0

I'm so confused. But it worked, thanks man. I will try to understand the code right now lol

0

You're welcome! If you got any more questions, let us know! :)

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)

4 comments

0

Doesn`t works

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. :)

0

He never said this was a server script so by default I thought it was a localscript.

0

And I already knew that, marketmanager1

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