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

Why does my sword only do damage once after hitting an enemy?

Asked by
TtuNkK 37
4 years ago

I am working on a sword right now and everything is fine and perfect until I found out that my sword can only deal damage once and once only. I made another question on how to make the sword only deal damage when it was clicked and it's fixed, but now it created another problem, which is this. All the animation works, the main problem is just that it's only doing damage once. Please help!

Local Script

local CanAttack = true
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local idle = char:WaitForChild("Humanoid"):LoadAnimation(script.idle)
local attack = char:WaitForChild("Humanoid"):LoadAnimation(script.attack)
script.Parent.Equipped:Connect(function()
    idle:Play()
    script.Parent.Activated:Connect(function()
        if CanAttack then
            idle:Stop()
            attack:Play()
            CanAttack = false
            idle:Play()
            wait(1)
            attack:Stop()
            CanAttack = true
            script.Parent.CanDamage.Value = true
        end
    end)
end)
script.Parent.Unequipped:Connect(function()
    idle:Stop()
end)

** Normal Script**

script.Parent.blade.Touched:Connect(function(p)
    if script.Parent.CanDamage.Value ==  true then
        p.Parent.Humanoid:TakeDamage(20)
        script.Parent.CanDamage.Value = false
    end
end)

1 answer

Log in to vote
1
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago

make the script like this (i think):

script.Parent.blade.Touched:Connect(function(p)
    if script.Parent.CanDamage.Value ==  true then
        script.Parent.CanDamage.Value = false
            p.Parent.Humanoid:TakeDamage(20 + math.random(1,20))
        script.Parent.CanDamage.Value = true
        end
end)

There was a CanDamage value blocked to make debounce so you can add some random number instead.

If this helped you, please mark this as the correct answer, or else comment below what error occurred in your output, Thanks :)

0
I tried out this new code, but I didn't even get a chance to left click to attack the dummy because it was taking lots of damage when it touched the blade. TtuNkK 37 — 4y
Ad

Answer this question