Detecting Player placement system


collisionPoint = object.PrimaryPart.Touched:Connect(function() end)
		collisionPoints = object.PrimaryPart:GetTouchingParts()
		
		-- Checks if there is collision on any object that is not a child of the object and is not a child of the player
		for i = 1, #collisionPoints do
			if not collisionPoints[i]:IsDescendantOf(object) and not collisionPoints[i]:IsDescendantOf(character) then
				setCurrentState(3)
				
				break
			end
		end
		
		collisionPoint:Disconnect()
		
		return collided

Can someone please help. My brain is not functioning. Basically how do I make it so if there is a Humanoid like other humanoids and not just the Character itself. Because I don’t want that to become a boundary. I want to make it so lets say I have an NPC walking around and the Player wanted to place something. I don’t want the NPC to be preventing you from placing the object other wise if I have too many NPC game will be impossible to build.

Hey there!

I have no idea what are you trying to achieve. Could you please make the description more detailed?

1 Like

You can use FindFirstAncestor() if you have NPC’s in a folder, or you could use IsDescendantOf() like you are already using. Its basically what you have for making sure you can’t collide with yourself just making sure other things can’t

if not collisionPoints[i]:IsDescendantOf(object) and not collisionPoints[i]:IsDescendantOf(character) and not collisionPoints[i]:FindFirstAncestor("NPC") then

won’t work :confused:

collisionPoint = object.PrimaryPart.Touched:Connect(function() end)

Do you put something in this function or nah?