Detect when inside a part (Zone)


I am trying to make a zone where when an NPC named “Ghost” walks into a part that is non-colidable, the NPC will turn invisible by this code:

	if hit.Parent.Name == "Ghost" then
		hit.Parent.Agro.Value = true
		for i,v in pairs(hit.Parent:GetDescendants()) do -- loop through everything in the character
			if v:IsA("BasePart") or v:IsA("Decal") then -- if it is a part
				v.Transparency = 1 -- make it invisible

What’s the issue?
The problem is that the code I used which was when touched and when touched ended, the script would constantly make the NPC invisible and then visible.

Is there a way to detect when an NPC is inside of part without using when touched and when touched ended?

1 Like

This simply isn’t true!
You are making the Objects Visible, not Invisible, Transparency has to be set from 0 - 1 for it to be Solid (0), Transparent (Anything between) or Completely Transparent (1)

  • You are able to Use a Region3 to detect if something is Inside something

  • You can also use :GetTouchingParts() to look for Parts that are touching

Ya, I pasted the wrong code. I have one set that makes it visible and then invisible. Thats not the issue thought. I don’t know how to detect an NPC colliding with a part.

You can use workspace:GetPartBoundsInBox()

or GetPartsInPart