.touched() not firing

Hello!
I was working on a certain project of mine and ran into a very simple issue:
a simple .touched() evenet was not firing.
Here is the script:

local DB = true

script.Parent.Hitbox.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum and DB then
		DB = false
		hum:TakeDamage(35)
		StabAnim:Play()
		task.wait(1)
		DB = true
	end
end)

In this case, when a player touched the part named Hitbox it should get damaged. Easy, right?
Well, it somehow doesn’t work. I checked if .CanTouch was enabled, which it is, and even tried to put a print("touch"), but it never gets there.

Here is an example with the print("touch") inside the script:

I seriously have no idea how to fix this.

First things first, are you sure the event is being connected and the script is not yielding before?

local DB = true

script.Parent.Hitbox.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum and DB then
		DB = false
		hum:TakeDamage(35)
		StabAnim:Play()
		task.wait(1)
		DB = true
	end
end)

print("connected event!")

Thanks for making me check, I forgot about a loop I didn’t put in another thread. Thanks again!

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