How to get touchingparts of a object without using :GetTouchingParts() or :GetPartsInPart()

So Iam trying to make a drop spawning scipt so I can spawn drops but I want to check if the new drop is near a other drop and if it is too close then I want to reposition the drop to a better place. My script is down bellow and pleace notice that I use a module script to define the function of dropping and I call the function inside a serversided scipt. Somehow if I use :GetTouchingParts or :GetPartsInPart it doesn’t give the list of parts… because it doesn’t print them inside the console.

Just to clarify more I use an invisable part in the drops which are grouped models and want to check if the invisable part is touching another invisable part of an other drop. If so then it needs to not break the while true loop so it gets repositioned, if it isn’t touching then the while true loop needs to break.

while true do
	local positionstable = GetPositions(droptype)
	local position = Vector3.new(positionstable[1], 0.5, positionstable[2])
	position = CFrame.new(position)
	drop:PivotTo(position)

	local touching = false
		
	for i, part in pairs(drop:WaitForChild("NoDropArea"):GetTouchingParts()) do
		print(part.Name)
		if part.Name == "NoDropArea" then
			touching = true
		end
	end
		
	if touching == false then
		break
	end
		
	wait()
end
	
1 Like

What I use is :GetPartBoundsInBox(), which basically just makes a table of every part touching the box radius which you can set to however big or small you want. For more information, read the documentation about it.

It returns with this error.
Can it be used in serversided scripts??

The code in the loop is now this:

for i, part in pairs(drop:WaitForChild("NoDropArea"):GetPartBoundsInBox(drop:WaitForChild("Mesh").CFrame, Vector3.new(8,8,8))) do
	print(part.Name)
	if part.Name == "NoDropArea" then
		touching = true
	end
end

You used it wrong, you use :GetPartBoundsInBox() like:

game.Workspace:GetPartBoundsInBox(CFrame,Size,OverlapParams)

Just put this in the while true do as it returns a table, then check for whatever is in that table.

1 Like

Thanks bro, it is working perfect now!

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