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

Are there any better ways to deal damage than this?

Asked by
neoG457 315 Moderation Voter
8 years ago
local enabled = false

script.Parent.Touched:connect(function(Hit)
    if not enabled then
        enabled = true
local human = Hit.Parent:findFirstChild("Humanoid")
        if (human ~= nil) then
                human.Health = human.Health - 30 
       wait(2)
           enabled = false
        end
    end
end)

This rarely works so I was wondering if there were anything better I could use. Thank you

2 answers

Log in to vote
1
Answered by
pwnd64 106
8 years ago

Try using human:TakeDamage(x)

local enabled = false

script.Parent.Touched:connect(function(Hit)
    if not enabled then
        enabled = true
local human = Hit.Parent:findFirstChild("Humanoid")
        if (human ~= nil) then
                human:TakeDamage(30)
       wait(2)
           enabled = false
        end
    end
end)


Should work.

Ad
Log in to vote
1
Answered by 8 years ago

Yes, use TakeDamage, like how @pwnd64 said, the thing is, his answer does not have enough information.


TakeDamage(float)

TakeDamage subtracts health from the humanoid. This only works if the player does NOT have a force field on. You can use TakeDamage to actually heal players by doing a negative number.

Humanoid:TakeDamage(30)


Final Product

local debounce = false

script.Parent.Touched:connect(function(part)
    local h = part.Parent:FindFirstChild("Humanoid")
    if h and not debounce then
        debounce = true
        h:TakeDamage(30)
        wait(3)
        debounce = false
    end
end)

Hope it helps!

0
Thanks to the both of you. I accepted pwnd64's answer cos he needs it more. neoG457 315 — 8y

Answer this question