Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to use debounce to stabilize touch ended?

Asked by 4 years ago
Edited 4 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.

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".)

0
use repeat wait() until ... recanman 88 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

0
Niceeee Fl3eandFlo3e 18 — 4y
Ad

Answer this question