How to use debounce to stabilize touch ended?
Asked by
5 years ago Edited 5 years ago
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.
01 | script.Parent.Part.Touched:Connect( function (hit) |
02 | local player = game:GetService( "Players" ):GetPlayerFromCharacter(hit.Parent) |
03 | game.ReplicatedStorage.TeleportGuiEvent:FireClient(player) |
04 | script.Parent.Part.TouchEnded:Wait() |
05 | game.ReplicatedStorage.UnteleportGuiEvent:FireClient(player) |
09 | script.Parent.Union.Touched:Connect( function (hit) |
10 | local player = game:GetService( "Players" ):GetPlayerFromCharacter(hit.Parent) |
11 | game.ReplicatedStorage.TeleportGuiEvent:FireClient(player) |
12 | script.Parent.Union.TouchEnded:Wait() |
13 | game.ReplicatedStorage.UnteleportGuiEvent:FireClient(player) |
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".)