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
11 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?

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

1 answer

Log in to vote
3
Answered by
Link43758 175
11 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:

1local click = tick()
2 
3mouse.Button1Down:connect(function()
4        if tick() - click < 0.8 then
5                print("double Click!")
6        end
7        click = tick()
8end)

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 — 11y
Ad

Answer this question