Make GUI visible on part touch

How can I make it so that when I touch a part, a GUI pops up?

I’m a beginner as you can tell

3 Likes

You want to insert a Server Script (basically just a Script, not a LocalScript) in the part that players will touch to see the GUI.
Then you want to use the following code below:

local part = script.Parent

part.Touched:Connect(function(hit) -- this event fires whenever something touches the part
	if hit.Parent:FindFirstChild("Humanoid") then -- if humanoid exists
		local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- gets the player from the character

		if player then -- if player exists
			if not player.PlayerGui.ScreenGui.Frame.Visible then 
				-- change the 'ScreenGui.Frame' to the actual name of your ScreenGui and the Frame (or it can be TextLabel or ImageLabel etc)
				player.PlayerGui.ScreenGui.Frame.Visible = true
			end
		end
	end
end)
5 Likes

Ok so it works!
However, I added a close button and I am running into an issue. After closing the frame, when i get off and get back on the part, the GUI no longer pops up…

Here is my button script

script.Parent.MouseButton1Down:Connect(function()
	script.Parent.Parent.Visible = false
end)
1 Like

maybe that’s because it’s a LocalScript (I assume)

maybe use a RemoteEvent?

Client:

Button.MouseButton1Click:Connect(function()
   game.ReplicatedStorage.RemoteEvent:FireServer(Button)
end)

Server:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, Button)
   Button.Visible = true
end)

also make sure that there’s a RemoteEvent in ReplicatedStorage

where do i store each script? not quite sure

1 Like

put the LocalScript in the button and change “Button” to script.Parent or make it a variable whatever

and Script in ServerScriptService of course

1 Like

not seeming to work…dont know what I did wrong.

do i have to name the remotevent anything?

I made the variable like so:
local Button = script.Parent

and then I copied the client script inside of my local script (which is inside my textbutton)

and the server script inside of a normal script (inside of serverscriptservice)

1 Like

We are not here to give you full scripts. @RocketB0ii Please dont spoonfeed him, say what he has to do in verbal form and let him write the code.

1 Like

Totally agreed.
The reason I see people provide full scripts are in expectations of getting marked their reply as “Solutions” and I don’t really know how “Solution” can help someone’s profile.

1 Like

Thats because when you make the Frame invisible using a local script, the server is not detecting it. I made an if statement checking if the Frame is not visible, and then the Frame will be visible.

You can try this code for the server script (that is inside the part):

local part = script.Parent

part.Touched:Connect(function(hit) -- this event fires whenever something touches the part
	if hit.Parent:FindFirstChild("Humanoid") then -- if humanoid exists
		local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- gets the player from the character

		if player then -- if player exists
		
			player.PlayerGui.ScreenGui.Frame.Visible = true
			-- change the 'ScreenGui.Frame' to the actual name of your ScreenGui and the Frame (or it can be TextLabel or ImageLabel etc)
		end
	end
end)

Its odd its like the open and close button messes up this server script inside the part. It works one time, and then once I close the GUI it stops working completely.

So the same problem is still occurring?

I believe i fixed it. thank you

Try doing this:

local GUI = -- your gui

script.Parent.Touched:Connect(function(touched)
    local Player = Players:GetPlayerFromCharacter(touched.Parent)
    if not Player then return end
	    gui.Visible == true
	else
		print("Physical Player Detected. Can't access playerGUI")
	end
end)
1 Like

I am also having the same issue but I want the gui to be visible for the client and not the whole server. How do you think I should approach this. Knowing that server scripts will make it visible to everyone in the server?

Why’d you have to bump :skull:
But as they said, use RemoteEvents.

[Solved] I tried that but doesn’t seem to work. Also, apologies for bumping. I just happened to search for a similar topic and didn’t want to make a duplicate.

1 Like