Take damage is not working

hitbox.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= player.Character and not hit.Parent:FindFirstChild("Value") then
			hit.Parent.Humanoid:TakeDamage(25)
			local value = Instance.new("BoolValue")
			value.Parent = hit.Parent 
			wait(0.5)
			value:Destroy()
		end
	end)

NPC does not take damage when this script is triggered

1 Like

does the hitbox.Touched play? Add a print(“touched”) outside the if statement and inside the if statement print(“damaging”)

The line of code where you told me to insert print does not print

Can you show the guts of your npc, is the humanoid named ‘Humanoid’?

also, maybe show a screenshot of where the hitbox is (if its inside another block it might not trigger a hit)

also, the original code you posted, can be a bit cleaner with attributes

hitbox.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= player.Character and hit.Parent:GetAttribute("Value") == nil then
		hit.Parent.Humanoid:TakeDamage(25)
		hit.Parent:SetAttribute("Value",true)
		wait(0.5)
		hit.Parent:SetAttribute("Value",nil)
	end
end)
hitbox.Touched:Connect(function(hit)
print("touched")
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= player.Character and not hit.Parent:FindFirstChild("Value") then
print("Damaging")
			hit.Parent.Humanoid:TakeDamage(25)
			local value = Instance.new("BoolValue")
			value.Parent = hit.Parent 
			wait(0.5)
			value:Destroy()
		end
	end)

Which one doesnt print

Both of the pieces of code do not print at all

There could be something wrong with the hitbox

My code didn’t have any prints, i was just showing how attributes could make it simpler without having to create a bool instance.

As I posted earlier, show some screenshots of the hierarchy of the npc
or where the hitbox is

Actually the touched print works however the damage does not

hitbox.Touched:Connect(function(hit)
	print(hit.Parent)
	if hit.Parent:FindFirstChild("Humanoid") then print("1")
		if hit.Parent ~= player.Character  then print("2")
			if hit.Parent:GetAttribute("Value") == nil then print("3")
				if hit.Parent:FindFirstChild("Humanoid") ~= nil then print("4")
				end	hit.Parent.Humanoid:TakeDamage(25)
				hit.Parent:SetAttribute("Value",true)
				print(hit.Parent:GetAttribute("Value"))
				wait(0.5) -- task.wait(0.5)
				hit.Parent:SetAttribute("Value",nil)
				print("5")
			end
		end
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.