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

How do I make a gui appear when the player is touching a part by a script?

I wanted to make a script where when a player touches a part a gui appears for the player who touched it but I can't I tried the script.

`script.Parent.Touched:Connect(function(hit)
if hit.parent:FindFirstChild("Humanoid") then
local blue = hit.Parent
game.StarterGui.Nice.Frame.Visible = true
end
end)

Sadly, it wont work, I searched it on the internet but none of them explained properly or I couldn't find it. Please help me make it work. Thank you if you do.

15 comments

0

rip u

0

and i am not grammar nazi

0

also ull have to list all the other things one is capable of ripping if u really hardcore person

0

Are you wanting to make it go away after the user stops touching the brick?

0

maybe

0

also if this really is not ur style u can always just change the GUI to a part or meshPart and make that transparent / not transparent when the player touches it. dont face ur problems, go around them

0

if you are going to do that, use the TouchEnded event

0

I was also trying to do that but I was focusing on making it appear on the brick first.

0

could be a problem with the how the roblox touch event works in the situation that its not a problem with ur script. If so make ur own touch event before continuing.

0

also there is typo on line 2; parent is uppercase "P"

0

alright just saying; says the grammar nazi

0

can somone please help me  

0

Why does it say that you want to touch a script? No such thing is possible.

0

o yeah!

0

actually check the name

2 answers

✓ Accepted answer

You requested the script for situation to show the GUI only when the player is touching the part. This is still a Local Script so put it inside your GUI.

  • I had some time so I created even more advanced script with more options just for you.

Updated Code:

local Workspace = game.Workspace

local Tpart = Workspace:WaitForChild("Part") -- Defines a way to a part.

local Players = game:GetService("Players")

-- Code starts here

local deb = 0

-- Makes the frame visible

Tpart.Touched:Connect(function(hit)

if deb == 0 then

deb = 1

local char = hit.Parent

if char then

local hum = char:WaitForChild("Humanoid")

if hum ~= nil then

print("Opening the Gui")

local Player = Players:GetPlayerFromCharacter(char)

local PlayerGui = Player.PlayerGui

local GuiToBeOpened = PlayerGui:WaitForChild("Nice")

GuiToBeOpened.Frame.Visible = true

end

end

end

end)

-- ?? Disappears the frame

Tpart.TouchEnded:Connect(function(hit)

if deb == 1 then

deb = 0

local char = hit.Parent

if char then

local hum = char:WaitForChild("Humanoid")

if hum ~= nil then

print("Opening the Gui")

local Player = Players:GetPlayerFromCharacter(char)

local PlayerGui = Player.PlayerGui

local GuiToBeOpened = PlayerGui:WaitForChild("Nice")

GuiToBeOpened.Frame.Visible = false

end

end

end

end)

8 comments

0

Thank you so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so much

0

how do I make it invisible when the person isn't on the part you dont need to answer it but thank you if you do

0

Alright

0

Do you wanna create a GUI visible only when the person is touching the part?

0

yes

0

Alright, I'll edit the script and notify you when I'm done.

0

THANK YOU SO SO SO MUCH

0

Your welcome

The StarterGui is the placeholder for the GUIs to be loaded later on for the different players.

Assuming by this "oopsie", I suppose that you are not very experienced into programming, so I'll keep the answer simple for you:

script.Parent.Touched:Connect(function(hit)
    -- Checking if it's a character(by having a humanoid)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if(hum) then
		-- method used to find the player
		local player = players:GetPlayerFromCharacter(Hum.Parent)
		if(player) then
			local gui = player.PlayerGui("Nice") -- your GUI's name
			gui.Frame.Visible = true
		end
	end
end)

When the player loads, the GUI is no longer inside of "StarterGui", but in "PlayerGui", found as a child of the player.

3 comments

0

It isn't showing me the frame and keeps on showing me an error which says attempt to index global 'Players' (a nil value) on line 6 thank you anyway the problem is easily fixed if you add game in front of it I wolud also like to say that on line 6 you put hum with the capital H when you put hum as a variable with a lowercase h and even after that nice isn't appart of the playergui eventough it is 

0

heh the "thank you anyway"

0

As I see in your code, you haven't defined a variable players you used to get the player. You could've used local Player = game.Players to get the Players service.

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