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

Double click instead of one click?

Asked by 5 years ago

Hi. I am trying to make a open gui. For the button that opens the gui, it needs 2 clicks instead of 1 click. How do i fix this?

function E()
    local S = script.Parent.Parent.Parent.ScreenGui.Shop
        S:TweenPosition(UDim2.new(0.272, 0,0.279, 0))
    script.Parent.Parent.Parent.ScreenGui.Shop.Visible = true

end
script.Parent.MouseButton1Click:Connect(E)

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago

Have a bool which keeps track of if the player clicked previously in the past two seconds:

playerClicked = false

function clicked()
    -- if this is the first time the players clicked, start the countdown 
    if(not playerClicked)then 
        playerClicked = true --set the player clicked state to be true
        wait(2) -- give the player two seconds to click again
        -- if they don't click in the next two seconds, reset playerClicked to false
        playerClicked = false
    else -- the player clicked twice in the span of two seconds, do the following code you wanted them to do when they clicked twice
        local S = script.Parent.Parent.Parent.ScreenGui.Shop
            S:TweenPosition(UDim2.new(0.272, 0,0.279, 0))
            script.Parent.Parent.Parent.ScreenGui.Shop.Visible = true
    end
end
script.Parent.MouseButton1Click:Connect(clicked)
Ad

Answer this question