This code is supposed to make a brick spawn every 10 seconds on a brick spawner (which it is parented under), with a slight chance of being a golden brick, and the brick is given an IntValue. Past bricks are supposed to be deleted.
The two problems I faced:
Multiple bricks spawn at a time
Past bricks are not deleted
Code:
while wait(10) do
for i,v in pairs(script.Parent:GetChildren())do
if v.Name == "Brick" then
v:Destroy()
else
bval = math.random(1,100)
if bval <= 99 then
brick = Instance.new("Part", script.Parent)
brick.Position = script.Parent.Position
brick.Size = Vector3.new(2,0.5,1)
brickval = Instance.new("IntValue")
brickval.Value = 1
elseif bval == 100 then
brick = Instance.new("Part", script.Parent)
brick.Position = script.Parent.Position
brick.Size = Vector3.new(2,0.5,1)
brick.BrickColor = BrickColor.new("New Yeller")
sparkles = Instance.new("Sparkles", brick)
brickval = Instance.new("IntValue")
brickval.Value = 25
end
end
end
end
For the aftermath, the game can be visited here.

3 comments
I don't understand the cleanup process. You're destroying objects with the name of "Brick", yet objects you create are not named such.
Well, that makes me an idiot lol. But I still don't get why multiple bricks spawn at a time...
Okay, now I'm actually very stupid, both problems were fixed, thanks.