Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I am having a problem with GUI Debounce on touch?

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

✓ Accepted answer
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?

4 comments

0

it works but it still clones multiple GUIs. I am confused. Do you have another solution for this?

0

Updated

0

And yes, it makes sense i see now.

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.