How can I make a humanoid keep taking continuous damage until they are dead?

NOTE: I have found a way to do this by using magnitude and repeat

I want to make a humanoid keep taking damage until they die, but I have no idea how to make a script that works like this.

Edit: I need the damage to play when the player touches a part.

Example of how I want the damage to work.

1 Like
while Humanoid.Health > 0 do
         Humanoid:TakeDamage(10)
         wait(.1)
end
1 Like
local Var = false
Var = true
while Var == true do
       if hit.Parent.Humanoid.Health >= 1 then

      hit.Parent.Humanoid:TakeDamage(1)

            else
             Var = false
      end
      wait()
end

Do not remove the wait() but play around with it to get that smooth effect you can also make them take 0.3 damage or something.

1 Like

For some reason the damage piles up on the wait and deals all the damage that has been piled up at once, is there a way to fix it so only the specified damage hurts you after the wait ends?

Did mines not work? It should.

Both of the code sent above worked, but both deals stacked damage

try this:

script.Parent.Touched:Connect(function(hit)

while hit ~= nil do

hit.Parent:WaitForChild("Humanoid"):takeDamage(3)

wait(1)

hit.Parent:WaitForChild("Humanoid"):takeDamage(3)

end

end)
its kind of delayed but works...or is it?
local Var = false
Var = true
while Var == true do
       if hit.Parent.Humanoid.Health >= 1 then

      hit.Parent.Humanoid:TakeDamage(1)

            else
             Var = false
      end
      wait(0.5)
end

this worked for me try it.

I KNOW WHAT YOUR PROBLEM IS! When using touched roblox thinks that the part was touched like 20 times.

I do this to prevent it.

if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Deb") == nil then
local Bool = Instance.new("BoolValue",hit.Parent)
Bool.Name = "Deb"

local Var = false
Var = true
while Var == true do
       if hit.Parent.Humanoid.Health >= 1 then

      hit.Parent.Humanoid:TakeDamage(1)

            else
            game.Debris:AddItem(Bool,0)
             Var = false
      end
      wait()
end

I didnt get the ends correct im on phone

Just make a edit test it :slight_smile:

Script error says “hit is an unknown global”

How are you detecting hit? Im confused.

Dont delete the Part.Touched:Connect(function(hit)

New error,

Error: (41,5) Expected 'end' (to close 'then' at line 25), got <eof>; did you forget to close 'do' at line 31?

Yea I tolded you I’m on phone so just find the ends and add them.

how about mine? did it worked? if not then im gonna delete the code

Hey, we are not here to spoon-feed code, maybe at least try this yourself or hire someone to do it for you. Just for future posts.

Now for about your problem…

I’d recommend using magnitudes for the part touched thingy cause not gonna lie touched is really bad for this. Also add a debounce so it doesn’t keep on doubling
Vector3 | Documentation - Roblox Creator Hub.
and use the other peoples code post above for the rest

Thanks, Kamlkaze_Kid

I think magnitude is little bit overkill for this.

How so? .Touched is bad practice and through past experience, magnitude works better

i tested it and it works:

script.Parent.Touched:Connect(function(plr)
	if plr.Name == "HumanoidRootPart" then -- If there are problems with this change to "Torso"
	local box = plr.Parent:FindFirstChild("Humanoid")
	if box then
		while box.Health > 0 do
			box:TakeDamage(10) -- Damage per wait
			wait(.1) -- Wait time
		end
		end
		end
end)

Only problem with this is that parts haves to touch torso else it won’t work, if you need tell me and i will update it soo it would work for legs and arms