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

I am having a problem with GUI Debounce on touch?

Asked by
Dexiber 272 Moderation Voter
4 years ago

I made a part that shows gui on touch with the help of @youtubemasterWOW , but I tried to add Debounce to it and its not working. I am pretty sure that I wrote it down right but I didn't get any errors but as I said, it didn't work. can someone help me? here is my code:

local debouce = false
local gui = game.ReplicatedStorage.EasyGUI
    local frame = gui.Frame

        local function onTouched(hit)
    if not debouce then
                debouce = true
             local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if player then
                local clone = gui:Clone()
                clone.Parent = player.PlayerGui
    wait(1.5)
    debouce = false
     end
    script.Parent.Touched:Connect(onTouched)
end

end


I need help on this a lot so that the players in my game don't find it annoying to keep on pressing to close button on the gui.

1 answer

Log in to vote
1
Answered by
Raccoonyz 1092 Donator Moderation Voter
4 years ago
Edited 4 years ago
local debouce = false
local gui = game.ReplicatedStorage.EasyGUI
local frame = gui.Frame

local function onTouched(hit)
    if not debouce then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then
            if player.PlayerGui:FindFirstChild("EasyGUI") == nil then
                debounce = true
                local clone = gui:Clone()
                clone.Parent = player.PlayerGui
                wait(1.5)
                debouce = false
            end
        end
    end
end
script.Parent.Touched:Connect(onTouched)

The issue you had was that you were activating the debounce for all parts. But you set the debounce to false inside the "if player" meaning that any non-player part would trigger it and keep the debounce as true.

Make sense?

0
it works but it still clones multiple GUIs. I am confused. Do you have another solution for this? Dexiber 272 — 4y
0
Updated Raccoonyz 1092 — 4y
0
And yes, it makes sense i see now. Dexiber 272 — 4y
0
Thank you! Dexiber 272 — 4y
Ad

Answer this question