Cannot make clones delete themself if they're clipping

I wanted to make a room generation script that also deletes the rooms that are clipping so there wont be two of them,but the touch event doesn’t detect them for some reason? How can i make it work?

Heres the generation script:

local RoomsFolder = game.ReplicatedStorage.ROOMS
local roomsamount = 1


local function Newroom()
	task.wait(0.1)
	for i,Lastroom in pairs(workspace:GetChildren()) do
		if Lastroom.Name == "TestroomLast" then
			Lastroom.Name = "Testroom"
			local Room = Lastroom
			
			for i,parts in pairs(Room:GetChildren()) do
				if parts.Name == "Roomend" then

					local Newroom = Room:Clone()
					local Endpart = parts
					
					task.wait(0.1)
					Newroom.Name = "TestroomLast"
					Newroom.Parent = workspace
					Newroom:SetPrimaryPartCFrame(Endpart.CFrame)

                    print("Making a connection...") 
					conectin = Newroom.Floor.Touched:Connect(function(hit) -- The thing that should remove clipping rooms
						if hit.Parent.Name == "TestroomLast" or hit.Parent.Parent.Name == "TestroomLast" then
							warn("Rooms clipping! Removing...")

							Newroom:Destroy()
							task.wait(10)
							conectin:disconnect()
						else
                            
							task.wait(10)
							conectin:Disconnect()
						end				
					end)	
					
					
					
				end
			end
			
		end
	end	
	
end
local i = 1
			
repeat
	task.wait(1)
	Newroom()
	i += 1

until i == 3

Whats inside the room:

And a video that shows the problem:

Thanks in advance.

instead of that, you can probably just use workspace:GetTouchingParts()

e.g.

if #workspace:GetTouchingParts(Newroom.Floor) > 0 then
    print("CLIPPING")
else
    print("NOT CLIPPING")
end

It says “GetTouchingParts is not a valid member of Workspace “Workspace””

I think theres a Parts in part function. Try using that. I dont remember the exact name.

Sorry, I usually mix up GetTouchingParts in GetPartsInPart.

GetTouchingParts is called on the basepart, NOT workspace, so it should be

if #Newroom.Floor:GetTouchingParts() > 0 then

cannot check it right now so gonna assume it works

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