How to remove GUI after player triggers proximity prompt?

What do you want to achieve?
I want the player to touch a part that triggers a ScreenGUI and then after they trigger a proximity prompt in a different part, the ScreenGUI disappears.

I’ve created the script to make the ScreenGUI appear when touching the part… but then it disappears after the player isn’t touching it anymore & I don’t know how to make it disappear after the proximity prompt in a different part is triggered.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr then
			if not plr.PlayerGui:FindFirstChild("GUIClonedfromtouchblock") then
				local clonedgui = script.Parent:FindFirstChildOfClass("ScreenGui"):Clone()
				clonedgui.Name = "GUIClonedfromtouchblock"
				clonedgui.Parent = plr.PlayerGui
				script.Parent.TouchEnded:Connect(function(hit2)
					if hit == hit2 then
						game.Debris:AddItem(clonedgui,0)
					end
				end)
			end
		end
	end
end)

Screen Shot 2022-07-11 at 1.15.12 PM

I’d really appreciate some help :slight_smile:

1 Like
game.Debris:AddItem(clonedgui,0)
--0? This means it gets removed instantly???
1 Like

I see what that problem was. I deleted that from the script.

Works or still the same thing?

1 Like

I figured out how to do it!

I inserted this script into the touch part:

guiName = "QuestBarHK" -- PUT THE NAME OF THE GUI HERE
gui = script:FindFirstChild(guiName)
script.Parent.Touched:Connect(function(touch) -- when touched do this
	if touch.Parent:FindFirstChild("Humanoid") then -- if the thing that touched has a humanoid in it then
		local person = touch.Parent -- person is the parent of the tocu, or so the person who touched you
		local player = game.Players:FindFirstChild(person.Name)	-- Get the player in the players folder
		if not player.PlayerGui:FindFirstChild(guiName)then -- if the gui is not in there yet..
			local g = gui:Clone() -- clone the gui that I have in this script...
			g.Parent = player.PlayerGui -- And put it in his/her playergui
		end
	end	
end)

Then I inserted this script into the Proximity Prompt part:

local ProxPromp = script.Parent.ChatProximity
guiName = "QuestBarHK"
ProxPromp.Triggered:Connect(function (player)
	if player.PlayerGui:FindFirstChild(guiName)then
		player.PlayerGui:FindFirstChild(guiName):Remove()
	end
end)

Thank you for your time and assistance :slight_smile: I appreciate your help!

1 Like

Glad i helped with that part, you did most of it tho!