I think I fixed it by changing it to:
local Part = script.Parent
local Players = game:GetService("Players")
local Folder = game.ReplicatedStorage.Rooms
local Rooms = Folder:GetChildren()
local function GenerateRoom(Hit)
local Char = Hit.Parent
local Player = Players:GetPlayerFromCharacter(Char)
if Player then
local RoomRNG = math.random(1, #Rooms)
local room = Rooms[RoomRNG]
local Clone = room:Clone()
Clone.Parent = workspace
Clone.PrimaryPart = Clone.StartPart
local cf = Part.CFrame
Clone:SetPrimaryPartCFrame(cf + cf.LookVector)
for _, v in ipairs(Clone:GetDescendants()) do
if v.Name == "GeneratePart" then
local Touching = v:GetTouchingParts()
if Touching[1] then
Clone:Destroy()
GenerateRoom(Hit)
end
end
end
Part:Destroy()
end
end
Part.Touched:Connect(GenerateRoom)