Hello!
I was wondering if anybody could help me!
For some reason, the debounce I currently have in place doesn’t seem to be working.
I want there to be a cooldown for when the print(“Entered”), which will be GUI effects, can be fired again after MouseLeave
If anyone can help, I would be very grateful! 
local Hovering = {}
ButtonFrame.MouseEnter:Connect(function()
if not Hovering[Button] then
Hovering[Button] = true
print("Entered")
end
end)
ButtonFrame.MouseLeave:Connect(function()
if Hovering[Button] then
print("Left")
wait(2)
Hovering[Button] = nil
end
end)
3 Likes
Why don’t you just use a regular debounce?
local debounce = false
ButtonFrame.MouseEnter:Connect(function()
if not debounce then
debounce = true
print("Entered")
end
end)
ButtonFrame.MouseLeave:Connect(function()
if debounce then
print("Left")
wait(2)
debounce = false
end
end)
2 Likes
because its in a module, and multiple buttons will be using this exact script. I just cut most of the script to make it easier to read

From what I can see in the button.MouseLeave you set the variable to nil so it still exists in the table you should completely remove it so when the mouse hovers it again the script will find the button in the table and will not set the denounce so on button.MouseLeave you want to use table.remove()
to remove the button that stops being hovered.
2 Likes
When I print the table after the MouseLeave, it prints the table as {} instead of {. . .}, so it doesnt seem to be staying in the table
You don’t have enough of the script. I imagine you have the table in the wrong scope. It should probably go at the top of the script.
1 Like
I didn’t feel comfortable giving the whole script thats all. The table is at the very top of the script.
The code you have presented works fine.
1 Like
If it worked, why would I ask for help?
It doesn’t work.
I said the code that you presented works fine. And it does. I just pasted it in Studio. It works fine. If something doesn’t work, then the problem is not with the code I was presented with.
1 Like
I realised that yes, the code does work. It works only when on an actual button, and not on a frame. Thats what it was originally. I changed it now to a button instead of frame. My bad 
1 Like
Actually every gui object has the events MouseEnter
and MouseLeave
1 Like