My cloning script would clone too many times. if anyone could help me, It would be highly appreciated!
local replicatedStorage = game:GetService("ReplicatedStorage")
local area = workspace.PotionSpawn
local areaSize = area.Size * 0.5
local min = area.Position - areaSize
local max = area.Position + areaSize
local part = replicatedStorage:WaitForChild("Potion")
--Some other code relating to the thing if needed
r = math.random(1,255)
g = math.random(1,255)
b = math.random(1,255)
partClone = part:Clone()
partClone.Handle.CFrame = CFrame.new(
math.random(min.X, max.X),
min.Y + part.Handle.Size.Y * 0.5,
math.random(min.Z, max.Z)
)
partClone.Handle.Potion.Color = Color3.fromRGB(r, g, b)
partClone.Parent = workspace.Potions
partClone.Name = 'Potion'
while wait() do
for i,v in pairs(workspace.Potions:GetChildren()) do
if v.Name == "Potion" then
print(i)
if i < 30 then
r = math.random(1,255)
g = math.random(1,255)
b = math.random(1,255)
partClone = part:Clone()
partClone.Handle.CFrame = CFrame.new(
math.random(min.X, max.X),
min.Y + part.Handle.Size.Y * 0.5,
math.random(min.Z, max.Z)
)
partClone.Handle.Potion.Color = Color3.fromRGB(r, g, b)
partClone.Parent = workspace.Potions
partClone.Name = 'Potion'
end
end
end
end