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

How to make a double click function for my script?

Asked by
Noxnuo 11
4 years ago

Hello, yes I asked the question 3 times. But I still dont know where I should put a double click function, and i dont know how I should make my double click function! Help?

My script for attacking:

1script.Parent.DamagePart.Touched:Connect(function(p)
2    if script.Parent.CanDamage.Value == true then
3    script.Parent.CanDamage.Value = false
4    p.Parent.Humanoid:TakeDamage(10)
5    wait(0.8)
6    script.Parent.CanDamage.Value = true
7    end
8end)

My LocalScript:

01local CanAttack = true
02 
03script.Parent.Equipped:Connect(function()
04    local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
05    local Slash = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash)
06 
07    Idle:Play()
08end)
09 
10script.Parent.Activated:Connect(function()
11    local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
12    local Slash = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash)
13 
14    if CanAttack == true then
15        Slash:Play()
View all 24 lines...

2 answers

Log in to vote
0
Answered by
poke7667 142
4 years ago

To make a double click function, you have to check if Activated is fired twice in a certain period of time. Use a variable to track how many times Activated has been fired and if its at least 2 within lets say 0.35 seconds, then run the function. If you need any help, feel free to reply to my answer.

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Add a counter to tell how many times you activated it or clicked. The guy above me said the same thing I just wanted to show you what that would look like.

01local CanAttack = true
02local AttackCounter = 0
03 
04script.Parent.Equipped:Connect(function()
05    local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
06    local Slash = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash)
07 
08    Idle:Play()
09end)
10 
11script.Parent.Activated:Connect(function()
12    AttackCounter = AttackCounter + 1
13    if CanAttack == true and AttackCounter == 2 then
14         local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
15     local Slash = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash)
View all 26 lines...

Answer this question