Frame wont open again when touched a part for the second time

I put a script into my frame I want visible with this script:

local p = game.Workspace.TouchDetectPart

p.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if script.Parent.Visible == false then
            script.Parent.Visible = true
        end
    end
end)

The script works perfectly fine, but whenever I click the gui away with my close button and I try touching the part again, the gui wont go open again.
I can’t figure out how this can be fixed.

  1. Ty, I had the close button in another script, which was local and put in the CloseButton I putted the function to close the frame in the script and it works, thanks you for your help!

Make sure that both scripts are local scripts & also make sure that the close button is making the same frame invisible.

local part = workspace:WaitForChild("TouchDetectPart")

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("HumanoidRootPart") then
		if not script.Parent.Visible then
			script.Parent.Visible = true
		end
	end
end)