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)
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)