-
What do you want to achieve? I want to use a singular button that registers a SingleClick event and a DoubleClick event, with the DoubleClick event having a higher priority than the SingleClick. For example, I want a GUI to open and display unit stats when you click on the unit’s button in the inventory. However, I also want users to be able to double click this same button to equip/unequip the unit.
-
What is the issue? The issue I’m having is getting the GUI to stay open once a double click is registered.
-
What solutions have you tried so far? What I’ve tried is
local Visible = false
local Clicks = 0
local Threshold = 2
local Time = 0.5
local LastClick = nil
local Equipped = false
Template.Clicked.MouseButton1Click:Connect(function()
if not Visible then
LastClick = tick()
Visible = true
else
local ElapsedClickTime = tick() - LastClick
if (ElapsedClickTime >= Time) then
Visible = false
print('Hiding')
else
Clicks += 1
local HitThreshold = (Clicks % Threshold) == 0
if (HitThreshold) then
Equipped = not Equipped
print(Equipped)
end
task.wait(Time)
Clicks -= 1
end
LastClick = tick()
end
end)
Anyone have any ideas how to approach this? The script I tried writing has the opposite effect - it closes when I double click but doesn’t do much about single click.