In my game, when you touch a part, it should open a gui, and when you step off the part, it should close the gui. This works, except for that if you move at all when on the part, the gui will flash on an off until you stop moving, which I don't want. Here is the script.
script.Parent.Part.Touched:Connect(function(hit) local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) game.ReplicatedStorage.TeleportGuiEvent:FireClient(player) script.Parent.Part.TouchEnded:Wait() game.ReplicatedStorage.UnteleportGuiEvent:FireClient(player) end) script.Parent.Union.Touched:Connect(function(hit) local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) game.ReplicatedStorage.TeleportGuiEvent:FireClient(player) script.Parent.Union.TouchEnded:Wait() game.ReplicatedStorage.UnteleportGuiEvent:FireClient(player) end)
I am figuring that there is a way I could use debounce to stabilize it, but if there are any other ways, I would like to hear them too. (Note, the part is really a model made out of two unions called "Part" and "Union".)
Figured it out on my own, instead of using debounce, I created a touch ended event and then continued to sense for touched events, and if the touched event happens, i'd return the function which would stop it, waiting for the touch ended to happen again, and stopping the gui from flashing.