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

How do you make a double clicked event for a tool?

Asked by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

For example, in a Roblox sword if you click once is slashes, if you click twice it lunges. I wanted to know how to do this.

Here's my idea, but will it work, and is there a better way to do it?

tool = script.Parent
tool.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()
        if tool.Clicked then --"Clicked" would be a bool value in the tool
            print("He double clicked!")
            tool.Clicked = false
        elseif not tool.Clicked then
            print("He only clicked once")
            tool.Clicked = true
            wait(0.5)
            tool.Clicked = false
        end
    end)
end)
0
try looking at the linked sword model in roblox and look at the script yurhomi10 192 — 10y

1 answer

Log in to vote
3
Answered by
Link43758 175
10 years ago

From reading the script, it looks like you're trying to set a BoolValue to true, wait 0.5 seconds and then set it to false. If the bool value is already true, then it means the player clicked within 0.5 seconds, meaning that the player double clicked. I don't see what would error with this, and it would be a perfect way to see if a player double clicked. Although I did find this on the forums, I cannot guarantee that it will work:

local click = tick()

mouse.Button1Down:connect(function()
        if tick() - click < 0.8 then
                print("double Click!")
        end
        click = tick()
end)

If you have any questions or need further help, feel free to contact me via commenting on this question. Hope I helped! :)

0
What does tick() do? Perci1 4988 — 10y
Ad

Answer this question