What I have is a folder in the workspace named CoinStorage and a Coin which is stored in ServerStorage. Every second, a coin is spawned into the workspace, in a folder named CoinStorageMain and the script is setup so that it should stop executing when the number of coins in CoinStorageMain is above 10 however this doesn't happen. The script keeps executing no matter how many coins there are and I don't know what else to try.
This code is in a script in ServerScriptService.
local coinsInStorage = workspace.Main.CoinStorageMain:GetChildren();
local coinModel = game:GetService("ServerStorage"):WaitForChild("CoinStorage"):WaitForChild("Coin")
while true do
if (#coinsInStorage <= 10) == true then
local copy = coinModel:Clone()
copy.Parent = workspace.Main.CoinStorageMain
copy.CFrame = CFrame.new(math.random(-31.5, 17.5), 1.5, math.random(-17.5, 28.5))
wait(1)
else
return nil
end
end

1 comment
The "== true" part is not necessary, so remove that. You are also only getting all the coins once. Try putting "coinsInStorage" inside the loop so it can update.