Player doesnt take damage

I have a script that when the part is touched it checks if its a player and then deals damage, but it doesnt deal damage. There are no errors.

Script:

local debounce = false
local damage = 20
	script.Parent.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild('Humanoid') and debounce == false then
			debounce = true
			hit.Parent.Humanoid:TakeDamage(damage)
            wait(10)
            debounce = false
		end
end)
2 Likes

If you are damaging players / npc’s, make sure the the script is a server script and not a local script
Either that or try doing

script.Parent.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild("Humanoid") and debounce == false then
            local humanoid = hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild("Humanoid") 
			debounce = true
			humanoid:TakeDamage(damage)
            wait(10)
            debounce = false
		end
end)

local domage = 20
local Interval = 10
local debounce = false

script.Parent.Touched:connect(function(hit)
if debounce == false then
debounce = true
if hit and hit.Parent and hit.Parent:FindFirstChild(“Humanoid”) then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
end
wait(Interval)
debounce = false
end
end)

Why not use the Humanoid:TakeDamage() event over Humanoid.Health = Humanoid.Health - amount

I dont know. its the same no.?

try this?

local debounce = false
local damage = 20
	script.Parent.Touched:Connect(function(hit)
    if not debounce then
    print("LOL!")
			debounce = true
            local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
            if hum then
           print("FOUND HUMANOID!!!")
			hum:TakeDamage(damage)
            wait(10)
            print("DEBOUNCE END!!")
            debounce = false
		end
end
end)

I had this same problem before, could you please check if the health is actually changing instead of it just being a Roblox’s GUI visual glitch?

To do this, head to the explorer when the game is running, and then enter your character’s Humanoid's properties, scroll down to “Health” and check if the value is changing when it’s supposed to.

It is a server script, and it is in a part in replicated storage

I checked it , the humanoid took 0 damage

It didnt work or print anything at all

i guess, but Humanoid:TakeDamage() its shorter

The Script what u wrote is working for me, if its not working for you i think you did something with your Humanoid, also try this:

local debounce = false
local damage = 20
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') and debounce == false then
		debounce = true
		hit.Parent.Humanoid.Health -= damage
			wait(10)
		debounce = false
	end
end)

That’s very strange, I tested your exact code in studio, and it worked for me. Maybe it’s the hit detection, or something related to a custom character in your game, if you made one.

Also, just want to point out that you don’t need to have a variable for dmg, use task.wait() instead of wait() (Its slower and less accurate), you can use and not debounce instead of and debounce == false, and that’s it.

Is the part in replicatedstorage? if so, is it :Clone()'ed? or just .Parent = workspace?

If you’re using a custom character, this is most likely work. Otherwise, it’s because the part is hitting accesories, not body parts. Try using this code

script.Parent.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild("Humanoid") and debounce == false then
            local humanoid = hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild("Humanoid") 
			debounce = true
			humanoid:TakeDamage(damage)
            wait(10)
            debounce = false
	end
end)

It is cloned, not parented anywhere.

I tested your code and it did to damage, but it’s random. One time I took 70 damage and another time took 30.

Also, the part is a MeshPart, and its in replicated storage, and this script is in it.

Yours worked! I dont really know why :TakeDamage doesnt work consistantly, but -= damage worked.

1 Like

try this

script.Parent.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild("Humanoid") and debounce == false then
            local humanoid = hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild("Humanoid") 
			humanoid:TakeDamage(damage)
            debounce = true
            wait(10)
            debounce = false
	end
end)