What do I want to achieve?
Create a fruit generation system like treelands
Whats the problem?
The loop will only happen one time
What solutions have I looked for
I am writing this code from another post about fruit generation like in treelands, but that post didn’t really help me.
local Spawns = game.Workspace:WaitForChild("FruitLocations")
local locations = Spawns:GetChildren()
for i, v in pairs(locations) do
print(v.Name)
local fruit = game.ReplicatedStorage.SpawnFood[v.Name]:Clone()
local folder = Instance.new("Folder")
folder.Name = "Fruits"
folder.Parent = v
print("New loops for "..v.Name)
while wait(0.01) do
local children = folder:GetChildren()
print(#children)
if #children <= 0 then
print("pass")
local randomizer = math.random(0,5)
print(randomizer)
if randomizer == 0 then
print("fruit added to "..v.Name)
fruit.Parent = folder
fruit.Anchored = true
local x = v.Position.X + math.random(-v.Size.X/2,v.Size.X/2)
local y = v.Position.Y + math.random(-v.Size.Y/2,v.Size.Y/2)
local z = v.Position.Z + math.random(-v.Size.Z/2,v.Size.Z/2)
fruit.Position = Vector3.new(x, y, z)
print("done")
end
end
end
end