[HELP] UI comes up once when you touch a Part

I came up with a script when you touch a Part a UI pop up. Every time I move away from the part and touch it again the UI will be visible.

What I want to do:
When you touch the Part and the UI comes up, if you click the close button when you touch the part again the UI will not show up anymore. (Basically the UI will only show once) Does that even make sense? :joy:

UI with close button

Script

Explorer

Thanks for helping me out! :grinning:

1 Like
local player = game:GetService("Players")
local Open = workspace.OpenGuiPart
local opened = false

Open.Touched:Connect(function(hit)
    if hit.Parent == player.Character and not opened then
        opened = true
        script.Parent.ScreenGui.Frame.Visible = true
    end
end)
1 Like

Thank you. By the way, is this an “add on” on the script I already have?

Yes, this is an add-on to your script.

1 Like

Just a side note, but you can actually format your code by doing this:

` ` ` --Add 3 of these symbols

` ` ` --And put 3 here to end your code

Anywho, there is a easier way to do this by creating a true/false variable like so:

local Player = game.Players.LocalPlayer
local Open = workspace.OpenGuiPart
local PlayerGui = Player:WaitForChild("PlayerGui")
local Open = false

Open.Touched:Connect(function(hit)
    if Open == false then
        PlayerGui.ScreenGui.Frame.Visible = true
        Open = true
    end
end)

And for the button as well, you can do this inside the same code:

local Button = PlayerGui.ScreenGui.Frame:WaitForChild("CloseButton")

Button.MouseButton1Click:Connect(function()
    Open = false
end)
1 Like