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

Why isnt this damage script damaging the player?

Asked by 4 years ago

i have been trying to make this script work for quite some time now and cant seem to get it to work. the script is supposed to damage the player who touched the brick and have a cool down so it doesent do 10 damage like every second and is a instant kill.

script.Parent.Touched:Connect(function(hit)
    local human = hit:findFirstChild ("Humanoid")
        if script.Parent.AttackCool.Value == true then
                script.Parent.AttackCool.Value = false
                human.Health = human.Health - 10
                wait(.1)
                script.Parent.AttackCool.Value = true
                print ("dmg taken")
        else
            wait()

    end
end)

AttackCool is a bool value in the part btw

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

I personally like to store my bools inside the script;

--Make sure it's a normal script...
local brick = script.Parent
local canDMG = brick:WaitForChild("AttackCool") --Waits until the boolvalue loads in

brick.Touched:Connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum and canDMG.Value then --No need to add the == true
        canDMG.Value = false
        hum:TakeDamage(10) --Deals 10 damage to the target humanoid
        print("Damage taken!")
        wait(0.1)
        canDMG.Value = true
    end
end)
Ad

Answer this question