So inside a model, I created 6 parts and I want to destroy or delete 5 of them here is the code but it's not working please help me fix it.
if #game.Workspace.Model:GetChildren() == 6 then local Model = game.Workspace.Model:GetChildren():Destroy() == 5 end
Reading the code I see that there are a few syntax issues. First, since the method GetChildren()
loops through the children of a parent and returns it in an array, a for loop would be a better way to destroy the parts, as just setting the quantity of parts equal to the Destroy()
function does not work.
local model = game.Workspace.Model --You would place your model name here local modelChildren = model:GetChildren() --Gets children of model for i = 1, 5 do --Loops through model's children specified times, in this case 5 modelChildren[i]:Destroy() --Destroys each part using the index value declared above end
Note: This only deletes the first 5 parts in your model, because it only loops through the first 5, to do the second 5 (2-6), you would do i = 2, 6
If you have any other questions just ask and I'll try to respond!