Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Are there any better ways to deal damage than this?

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

✓ Accepted answer

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.

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!

1 comment

0

Thanks to the both of you. I accepted pwnd64's answer cos he needs it more.

This discussion is preserved as it was. New answers, comments, and votes are closed.