I have this script that opens a ScreenGui when the detector is touched. It works perfectly the first two times, but the thing is that after two times of opening and closing it doesn't work anymore. Here is my script
Players = game:GetService("Players")
LocalPlayer = Players.LocalPlayer
PlayerGui = LocalPlayer.PlayerGui
Detector = game.Workspace.RoomDetector1
RS = game:GetService("ReplicatedStorage")
ShopOpen = false
Detector.Touched:Connect(function(touch)
if ShopOpen == false and touch.Parent.Name==LocalPlayer.Name then
RS.Rooms:Clone().Parent = PlayerGui
ShopOpen=true
end
end)
game.Players.LocalPlayer.PlayerGui:WaitForChild("Rooms").Frame.Close.MouseButton1Click:Connect(function()
ShopOpen = false
print ("Test")
end)
I also noticed that it only prints test once. This is really weird. Help is appreciated.

4 comments
You don't have a loop in here even.
ohhhhh but how come it runs a second time without a loop?
Chase, do you know how catastrophic a touched event would be if you ran it on a loop? Imagine this, right. You have one touched function, and you put it inside a loop. Now, every 0.04 seconds, it multiplies the touched function. Now, when you touch the part that you gave the event to, it runs a billion times in one touch. Would you really want that?
Add a debounce