This is my problem. I made an script that makes the tiles disappear randomly but when I used the math.random(), I not working. I put some parts that named Tile there are 350 Parts named Tile that Part needs to be destroy in random. So the Parent of the Tile are Tiles which is model. The parent of the model is a Model named RandomDestoyedTiles. I put a script under the Model named RandomDestoyedTiles. I put this lines of the code.`
local Model = script.Parent local Tiles = Model.Tiles local Tile = Tiles:GetChildren() local Tilecopy = Tile[math.random(1,#Tile)] while true do Tilecopy:Destroy() wait(3) end
Is this correct? I mean Do I have typed wrong code. I have make my own lines to think what happening so i used math.random() and while true do. But why i not worked, can you tell me what happen , if worked it is only one Part destroyed.No errors at the output.Why?
You're only picking one object once, then repeatedly trying to destroy the same object that was already picked. Try this:
```lua local Model = script.Parent local Tiles = Model.Tiles
while true do local children = Tiles:GetChildren() -- Avoid errors when using math.random on an old table just in case. if #children > 1 then local TileCopy = Tile[math.random(1, #children)] TileCopy:Destroy() else --// No more children to destroy print("No more children to destroy") end wait(3) end ```