I wanted to make randomly generating tiles,with the spawn and the exit only generating one time,but when i try running the generation i get an error saying:
“The Parent property of Spawn/Exit is locked, current parent: NULL, new parent Workspace”
How can i fix that?
Heres the script:
local Placeholders = game.Workspace.PlaceHolders
local rooms = game:GetService("ReplicatedStorage"):WaitForChild("Setpieces"):GetChildren()
local HasSpawn = false
local HasExit = false
task.wait(5)
for i, placeHolder in pairs(Placeholders:GetChildren()) do
local chosenroom = rooms[math.random(1,#rooms)]:Clone()
if chosenroom.Name == "Spawn" then -- Spawn
if HasSpawn == false then
HasSpawn = true
chosenroom.PrimaryPart = chosenroom:WaitForChild("Carpet")
chosenroom:SetPrimaryPartCFrame(placeHolder.CFrame)
else
chosenroom:Destroy()
repeat
local chosenroom = rooms[math.random(1,#rooms)]:Clone()
if chosenroom.Name == "Spawn" then
chosenroom:Destroy()
end
until chosenroom.Name ~= "Spawn"
end
elseif chosenroom.Name == "Exit" then -- Exit
if HasExit == false then
HasExit = true
chosenroom.PrimaryPart = chosenroom:WaitForChild("Carpet")
chosenroom:SetPrimaryPartCFrame(placeHolder.CFrame)
else
chosenroom:Destroy()
repeat
local chosenroom = rooms[math.random(1,#rooms)]:Clone()
if chosenroom.Name == "Exit" then
chosenroom:Destroy()
end
until chosenroom.Name ~= "Exit"
end
else -- Normal room
chosenroom.PrimaryPart = chosenroom:WaitForChild("Carpet")
chosenroom:SetPrimaryPartCFrame(placeHolder.CFrame)
end
placeHolder:Destroy()
chosenroom.Parent = workspace -- Error here
end