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

How do I make it so that my Tool does damage only when I click?

Asked by 5 years ago
Edited 5 years ago

Aight so the animation when I click plays when i press but the hit the :TakeDamage(60) happens right away when I don't click like if I just get the Handle(The handle is a square part ) it does damage right away how can i make it so that only if i click it does damage

tool = script.Parent
Handle = tool:WaitForChild("Handle")
player = game.Players.LocalPlayer
mouse = player:GetMouse()
Animation = tool:WaitForChild('Anime')
AnimationTime  = true
tool.Equipped:Connect(function()
    print(tool)

end)

tool.Activated:Connect(function()
    if AnimationTime then
        AnimationTime = false
        local AnimationPlay = player.Character.Humanoid:LoadAnimation(Animation)
        AnimationPlay:Play()

        wait(1)
        AnimationTime = true

    end
end)


Handle.Touched:Connect(function(hit)
    debounce = false
    if hit and tool.Activated then
        Humanoid = hit.Parent:FindFirstChild('Humanoid')
        if Humanoid then
            Humanoid:TakeDamage(60)

            wait(1)


        end
    end
end)
0
Please provide some explanation to your code and what you're trying to accomplish. RayCurse 1518 — 5y
0
Im trying to make it so that only when I click it does damage because If i have that tool out and it touches a Humanoid it does damage and instakils right away User#22788 5 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

This is because you didnt make a boolean for the Touched event when it should fire, so it just fires outright and putting the Activated event in the if statement wont do anything. You can fix this by just using a boolean like what i said.

local tool = script.Parent
local Handle = tool:WaitForChild("Handle")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Animation = tool:WaitForChild('Anime')
local AnimationTime  = true
local canTouch = false

tool.Equipped:Connect(function()
        print(tool)
end)

tool.Activated:Connect(function()
    if not AnimationTime then
        AnimationTime = false
        local AnimationPlay = player.Character.Humanoid:LoadAnimation(Animation)
        AnimationPlay:Play()
    canTouch = true
    AnimationPlay.Stopped:Wait()
        AnimationTime = true
    canTouch = false

    end
end)


Handle.Touched:Connect(function(hit)
    local Humanoid = hit.Parent:FindFirstChild('Humanoid')
        if Humanoid and canTouch == true then
            Humanoid:TakeDamage(60)
        end
    end
end)
0
At line 29 are there suposed to be two == signs? User#22788 5 — 5y
0
btw it doesn't work idk if u wanted me to add on to it or copy and paste it User#22788 5 — 5y
0
oops ya theres suppose to be 2 == User#23365 30 — 5y
0
changed it User#23365 30 — 5y
View all comments (2 more)
0
for some reason it does not damage or play the aniimation User#22788 5 — 5y
0
are there any errors User#23365 30 — 5y
Ad

Answer this question