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

How can i make a GUI pop-up on the Touched event of a part?

I have been looking on many tutorials online since i'm kinda new to Lua and none of the codes presented has worked for me, i found a promising one but when i gave it a try it didn't work

Here's the code:

game.Players.PlayerAdded:Connect(function(plr)
script.Parent.Touched:connect(function(hit)
 if hit.Parent:FindFirstChild("Humanoid") then
  plr.PlayerGui.questchat.Teleport.Visible = false
  wait(2)
  plr.PlayerGui.questchat.Teleport.Visible = true
 end
end)
end)?

At first i thought it was a problem with the names of the GUI and frames but everything checks out and still no output, no change of properties and no popup or closure of the GUI

2 comments

0

Are you using filtering enabled?

0

That tutorial is bad.

2 answers

✓ Accepted answer
local Players = game:GetService('Players')

script.Parent.Touched:connect(function (hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		local char = hit.Parent
		if Players:FindFirstChild(char.Name) then
			local plr = Players:FindFirstChild(char.Name)
			plr.PlayerGui.questchat.Teleport.Visible = false
  			wait(2)
		 	plr.PlayerGui.questchat.Teleport.Visible = true
		end
	end
end)

-- Didn't test but that should be right

1 comment

0

Yep it worked, ty very much

Hello. This script will only work without filtering enabled.

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then --checks if it is a player
		local char = hit.Parent --gets the character
		local plr = hit.Parent::GetPlayerFromCharacter(char) --gets the player who touched the part
		plr.PlayerGui.questchat.Teleport.Visible = true --Sets the gui visible
	end
end)

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