Hi! I’m cloning rings and putting them into the workspace folder, and I’m trying to have a limit to how many cloned rings can be at once in the folder. The limit for now is supposed to be 10, but for some reason the script stops cloning and putting rings into the workspace folder at 5 rings.
I tried solving the issue by printing the amount of rings inside the folder, but the counter is completely wrong.
Here is the code:
local ServerStorage = game:GetService("ServerStorage")
local interval = 5
local obj = script:WaitForChild("Ring")
local folder = workspace:FindFirstChild("Rings")
local count = 0
while count <= 10 do
for i, v in pairs(workspace:WaitForChild("Rings"):GetChildren()) do
if v.Name == "RingClone" then
count += 1
end
end
print(count)
local clone = obj:Clone()
clone.Name = "RingClone"
clone.Parent = folder
task.wait(interval)
end
This is print for the amount of rings in the folder from the output (For some reason it jumps from 1 to 3, then 6, and so on. While it is supposed to be counting by 1,2,3,4,5,6,7,8,9,10.):
Then here is the RingFolder located in the workspace (The script stopped cloning the rings and putting into the folder at 5 rings):
Can someone please explain and help me on this issue? Thanks.