:GetTouchingParts() not working

I’m trying to make a room generation system but the rooms keep clipping trough each other, so i tought to give every type of room a bounding box and detecting if 2 bounding boxes hit each other using :GetTouchingParts() but it isn’t working.

Script:

local og = workspace.OriginalPoint
local rooms = game.ServerStorage.Rooms

for i = 1 ,100 do
	local selectedroom = rooms:GetChildren()[math.random(1, #rooms:GetChildren())]
	local c = selectedroom:Clone()
	c.Parent = workspace
	c:SetPrimaryPartCFrame(og.CFrame)
	local touchingparts = c:FindFirstChild("BoundingBox"):GetTouchingParts()
	for i_,v in ipairs(touchingparts) do
		if v.Name == "BoundingBox" then
			c:Destroy()
		end
	end
	c.Name = c.Name.. i
	c:FindFirstChild("End").Transparency = 1
	c:FindFirstChild("Start").Transparency = 1
	c:FindFirstChild("End").Transparency = 1
	og = c:FindFirstChild("End")
end

I am pretty sure this is the problem here, because you’re telling the script, for 100 times, position the selectedroom to just one same CFrame, causing the selectedroom to be destroyed everytime because it’s always at the same CFrame occupied by a previously positioned selectedroom.

No i set the og to the spawned rooms end at the end of the loop.

1 Like

The generation is working but only the :GetTouchingParts() part isn’t working.

Hmm, sounds like a hitbox issue. Why don’t you try one of these methods?

Or

The problem is that the rooms are still clipping trough each other, even tough i scripted it to not.

Probably because of the room’s End part, since that part is part of the room, when you try to position a new selectedroom to that End part’s position, GetTouchingParts() should detect something is clipping the newly added selectedroom, therefore destroying it.

No, that cant be the problem the parts are perfectly sized to not touch each other if its a new room.
If this would be the case then i would know because i am printing the touching part and it just prints nothing. (printing isn’t in the script i posted)

Turning cancollide on somehow fixed it, but the problem now is that the player cant walk trough the rooms :/.

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