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
3 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:

script.Parent.DamagePart.Touched:Connect(function(p)
    if script.Parent.CanDamage.Value == true then
    script.Parent.CanDamage.Value = false
    p.Parent.Humanoid:TakeDamage(10)
    wait(0.8)
    script.Parent.CanDamage.Value = true
    end
end)

My LocalScript:

local CanAttack = true

script.Parent.Equipped:Connect(function()
    local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
    local Slash = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash)

    Idle:Play()
end)

script.Parent.Activated:Connect(function()
    local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
    local Slash = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash)

    if CanAttack == true then
        Slash:Play()
        Idle:Stop()
        CanAttack = false
        wait(0.8)
        Slash:Stop()
        Idle:Play()
        CanAttack = true
        script.Parent.CanDamage.Value = true
    end
end)

2 answers

Log in to vote
0
Answered by
poke7667 142
3 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 3 years ago
Edited 3 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.

local CanAttack = true
local AttackCounter = 0

script.Parent.Equipped:Connect(function()
    local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
    local Slash = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash)

    Idle:Play()
end)

script.Parent.Activated:Connect(function()
    AttackCounter = AttackCounter + 1
    if CanAttack == true and AttackCounter == 2 then
         local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
     local Slash = script.Parent.Parent.Humanoid:LoadAnimation(script.Slash)
    AttackCounter = 0
        Slash:Play()
        Idle:Stop()
        CanAttack = false
        wait(0.8)
        Slash:Stop()
        Idle:Play()
        CanAttack = true
        script.Parent.CanDamage.Value = true
    end
end)

Answer this question