Soo I was trying to use a kinda older system to create a bush generating system but the system works, but it stops working when the part/bush becomes nil in a folder in the workspace, here is the code:
--// CONFIGURATIONS \\--
local Colors = {"Medium green", "Sea green", "Camo"}
local GenerationCheck = true
--// VARIABLES \\--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Bush = ServerStorage.Bushes.Bush
local RandomPosition = Vector3.new(12.124 + (46.852 - 12.124) * math.random(), 0.2, 17.065 + (45.325 - 17.065) * math.random())
--// MAIN CODE\\--
local function GenerateBush()
local BushC = Bush:Clone()
local Template = game.Workspace.Template.Main
BushC.Parent = game.Workspace.Bushes or workspace.Bushes
BushC.Name = "Bush"
BushC.Position = RandomPosition
BushC.BrickColor = BrickColor.Random(Colors)
end
local function AddGeneratedBush()
for i,Bush in ipairs(game.Workspace.Bushes:GetChildren()) do
if not Bush then
print("Bush Destroyed!")
GenerateBush()
else
print("Bush Safe!")
end
end
end
-- generate the bushes
if GenerationCheck then
while wait(2) do
AddGeneratedBush()
end
end