I'm trying to make an enemy NPC script, everything else in the script works except this part of the code:

for _, Child in pairs(script.Parent:GetChildren()) do
	if Child:FindFirstChild("DangerZone") then
		Child.Touched:connect(Hit)
		print("Player has been hit")
	end
end 

I'm still learning how GetChildren works, so sorry if I'm using it wrong or if I need to use something else.

5 comments

0

Tell me if I need to post the whole script, sorry for the inconvenience.

0

Is Hit a custom function you made? Or is it first called there?

0

Yes, Hit is a function before this line of code. It's a function that damages the player.

0

i dont see a problem here, can u show us the hit function?

0

I've posted the whole script instead