Ok so excuse me if this is a dumb question.
Im new to lua and I want to make a ontouch function which basically shows the gui when you touch it.
I did the following code:
script.Parent.Touched:connect(function(hit)
game.Players[hit.Parent.Name].PlayerGui.SellGUI.Main.Visible = true
end)
In a regular script.
When it shows the gui and I click the close button, then walk off the part and go back on, it doesnt show. All the close button does is make SellGUI.Main.Visible to false. I dont understand why this isnt working?
I literally cannot understand why this isnt working, and probably someone who knows lua can easily tell what the mistake probably is, but im trying to self learn.
So my question is, what did I do wrong? Is there a reason why this isnt working? Why does this gui only appear once?
Im new to this site and lua, so excuse any mistakes I did on this question or code.
Thanks to anyone who helps.

1 comment
It's important to know that when dealing with touched events you'll need a debounce. Otherwise your script will run multiple times and produce unwanted results.