Humanoid only taking Damage at once

  1. What do you want to achieve?
  • When a player touches the killing part, they only take damage once for each time they touching it, but when they stop touching it, the killing part will return to normal (if player touches it again, they still taking damages)

  • Other players still taking damage if they touches that killing part (which means if both players touching the killing part, they both get damaged)

  1. What is the issue?
    The issue is like this :
    image

  2. What solutions have you tried so far?
    I already checked out some topic like “Humanoid only taking damage once”, Like this script one, but it doesn’t seems like what i want

This is also my script, I know something is wrong with it but i don’t know where did i wrong

		script.Parent.Blade.Touched:Connect(function(target)
			if target.Parent ~= char and Damaged == false then
				if target.Parent:FindFirstChild("Humanoid") then
					local humanoid = target.Parent:FindFirstChild("Humanoid")
					if humanoid then
						for i = 1, #humanoid do
							humanoid[i]:TakeDamage(math.random(12-24))
						end
					elseif not humanoid then
						return
					end
				end
			end
		end)

For clarity, can you please show me which line is line 57? I believe I have some sort of idea as to why your code is not working.

Its only taking damage once because there is only one humanoid. You are looping through one humanoid, which is why its only taking damage once.

When you use the number sign, it means its converting however many children are in the variable to numbers. So if I have two objects in my variables, the # would be two when converted.

You also can’t get the length of one instance, because its only one object. You would need a table for that. (:GetChildren)

script.Parent.Blade.Touched:Connect(function(target)
			if target.Parent ~= char and Damaged == false then
				if target.Parent:FindFirstChild("Humanoid") then
					local humanoid = target.Parent:FindFirstChild("Humanoid")
					if humanoid then
						humanoid:TakeDamage(math.random(12, 24))
					elseif not humanoid then
						return
					end
				end
			end
		end)

This is the line 57

for i = 1, #humanoid do

There’s no need to loop through the (number?) of humanoids, when at max there will only be one per .Touched() event.

No, i already tried that method, It didn’t work well
It’s a sword, which mean you have to swing it to deal damages, at this case, the sword is the part are moving. So if you were stand still, you still taking over damage.
The problem is the blade of the sword always found the same Humanoid and deals of more damage on it

I was just fixing your loops. The script works. Its just because it doesn’t have a debounce.

local debounce = false
script.Parent.Blade.Touched:Connect(function(target)
			if target.Parent ~= char and Damaged == false and debounce == false then
                                debounce = true
				if target.Parent:FindFirstChild("Humanoid") then
					local humanoid = target.Parent:FindFirstChild("Humanoid")
					if humanoid then
						humanoid:TakeDamage(math.random(12, 24))
					elseif not humanoid then
                                                 wait(0.5)
                                                debounce = false
						return
					end
				end
			end
                        wait(2)
                        debounce = false
		end)

There’s no need to use debounce, you can just use Damaged for the boolean
In this case, your script still have some unexpected points like adding more damages for the humanoid or making lag, but i can fix it by myself. Thanks for your helps :smiley::+1:

What do you mean by damage for the boolean? It waits and has a boolean to not kill the person instantly.