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

Can someone help me with my "Pop Up GUI" code? The GUI doesn't pop up.

I am trying to make a script where when you touch a certain part, a GUI pops up on your screen. However, it has not been working in thew actual game, and not in the playtest. Please help me! This is my code:

 script.Parent.Touched:Connect(function(hit)
	if hit.Name == "Left Foot" then
		game.StarterGui.Shop.Frame.Visible = true
	end
end)

2 answers

✓ Accepted answer

Please read this short article excerpt.

####TL;DR:

StarterGui is not the authentic household of the GUI Objects, to actively modify the local User Interface, you have to access the PlayerGui container of a Player Object. Fortunately, the .Touched signal's Hit parameter can be used to pull a Player Object from the Instance of contact, which is a piece of your Character Rig.

local Players = game:GetService("Players")

local Part = script.Parent

local function OpenGui(Hit)
	local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
	if (Humanoid) then
		local Player = Players:GetPlayerFromCharacter(Hit.Parent)
		if (Player) then
			local PlayerGui = Player:WaitForChild("PlayerGui")
			local Shop = PlayerGui:WaitForChild("Shop")
			local Frame = Shop:WaitForChild("Frame")
			Frame.Visible = not (Frame.Visible)
		end
	end
end

Part.Touched:Connect(OpenGui)

If this works for you, don't forget to accept this answer!

14 comments

0

It works, but only once. How would I make it so it works multiple times?

0

What do you mean only once?

0

If I step on it, then close the gui, it doesn't pop up again when I step on it.

0

How are you closing the GUI

0

I have an X Button script that makes the GUI invisible

0

Make sure you're not making the Shop Gui invisible. Otherwise this will also cause the Frame to disappear regardless of the visibility.

0

Then how would I close it without using the X Button or making it invisible?

0

Are you gonna respond?

0

alright im going to bed see u tommorow if you answer

0

Try the code above, check the output if it doesn’t work.

0

hang on

0

wait nvm i know what u mean)

0

i get nothing in the output when i open or close the gui

0

can we solve this tommorow? I need to go to bed.

This problem was fixed by @Feahren, so thanks to them.

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