so my module wont work it spawns seeds on soil types and reproduces
but it only spawns on 1 soil type
local RandomLocation = {}
-- Helper function to create a new seed
for i,v in pairs(game.Workspace["Types_o'_soil"]:GetChildren()) do
local function createSeed(position)
local seed = Instance.new("Part")
seed.Name = "Seed"
seed.Anchored = true
seed.CanCollide = false
seed.Position = position
seed.BrickColor = BrickColor.new("Brown")
seed.Material = Enum.Material.SmoothPlastic
seed.Size = Vector3.new(0.5, 0.5, 0.5)
seed.Parent = workspace
return seed
end
-- Plant a seed and grow it into an adult plant
function RandomLocation:plantSeed(seed)
-- Ensure a valid seed is provided
if not seed or not seed:IsA("BasePart") then return end
local position = seed.Position
-- Create the plant
local plant = Instance.new("Part")
local dnaFolder = game.ReplicatedStorage.Dna:Clone()
dnaFolder.Parent = plant
plant.Name = "Plantling"
plant.Anchored = true
plant.CanCollide = false
plant.Position = position
plant.BrickColor = BrickColor.new("Camo")
plant.Material = Enum.Material.SmoothPlastic
-- Apply DNA-based size mutation
local width = dnaFolder.Width.Value * (math.random(80, 120) / 100)
local height = dnaFolder.Height.Value * (math.random(80, 120) / 100)
plant.Size = Vector3.new(width * 0.5, height * 0.5, width * 0.5)
plant.Parent = workspace.Trees
-- Destroy the seed
seed:Destroy()
-- Simulate growth to adult plant
task.wait(10)
self:growToAdult(plant)
end
function RandomLocation:growToAdult(plantling)
-- Ensure a valid plantling
if not plantling or not plantling:IsA("BasePart") then return end
-- Double size to represent growth
plantling.Name = "Adult_Plant"
plantling.Size = plantling.Size * 2
-- Drop seeds around the adult plant
local soil = v
if not soil then return end
for _ = 1, 3 do
local seedPosition = soil.Position + Vector3.new(
math.random(-soil.Size.X / 2, soil.Size.X / 2),
0.7, -- Ensure seeds are above the soil
math.random(-soil.Size.Z / 2, soil.Size.Z / 2)
)
local seed = createSeed(seedPosition)
-- Simulate planting the new seed
task.wait(5)
self:plantSeed(seed)
end
end
function RandomLocation:run()
local soil = v
if not soil then return end
-- Generate an initial seed at a random position
local position = Vector3.new(
soil.Position.X + math.random(-soil.Size.X / 2, soil.Size.X / 2),
soil.Position.Y + 1, -- Offset to avoid intersection
soil.Position.Z + math.random(-soil.Size.Z / 2, soil.Size.Z / 2)
)
local seed = createSeed(position)
-- Start the planting process
task.wait(5)
self:plantSeed(seed)
end
end
return RandomLocation