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.