I have this module script that clones objects into workspace. For each function I ran 2 for loops so that the first for loop will always make sure a certain object gets cloned, while the second for loop will clone random items from a table.
However I have noticed that the function does not produce the correct amount of cloned objects and always produces less.
local drops = {}
--<Variables>--
local wood = game.ServerStorage.ItemDrops.Wood
local seed = game.ServerStorage.ItemDrops.Seed1
--<Tables>--
local TreeDrops = {wood, seed}
function drops.SmallTree()
for i = 1, 2 do
wood:Clone()
wood.Parent = game.Workspace
wood:MoveTo(script.Parent.Handle.Position + Vector3.new(math.random(-3, 3), 0, math.random(-3, 3)))
end
for i = 1, 2 do
local ItemDrop = math.random(1, # TreeDrops)
local Item = TreeDrops[ItemDrop]
local dropped = Item:Clone()
dropped.Parent = game.Workspace
dropped:MoveTo(script.Parent.Handle.Position + Vector3.new(math.random(-3, 3), 0, math.random(-3, 3)))
end
end
function drops.MediumTree()
for i = 1, 3 do
wood:Clone()
wood.Parent = game.Workspace
wood:MoveTo(script.Parent.Handle.Position + Vector3.new(math.random(-3, 3), 0, math.random(-3, 3)))
end
for i = 1, 3 do
local ItemDrop = math.random(1, # TreeDrops)
local Item = TreeDrops[ItemDrop]
local dropped = Item:Clone()
dropped.Parent = game.Workspace
dropped:MoveTo(script.Parent.Handle.Position + Vector3.new(math.random(-3, 3), 0, math.random(-3, 3)))
end
end
function drops.BigTree()
for i = 1, 4 do
wood:Clone()
wood.Parent = game.Workspace
wood:MoveTo(script.Parent.Handle.Position + Vector3.new(math.random(-3, 3), 0, math.random(-3, 3)))
end
for i = 1, 4 do
local ItemDrop = math.random(1, # TreeDrops)
local Item = TreeDrops[ItemDrop]
local dropped = Item:Clone()
dropped.Parent = game.Workspace
dropped:MoveTo(script.Parent.Handle.Position + Vector3.new(math.random(-3, 3), 0, math.random(-3, 3)))
end
end
return drops
I wanted the first function to produce 4 clones, the second 6 clones, and the third 8 clones. However it doesnt seem to work 100%

2 comments
Did you count the clones correctly?
The first one produces 3 clones instead of 4, I know cause I looked at workspace in explorer, plus the second one only produces 4 instead of 6, it seems all of the functions produce less than what I want it to produce.