I'm trying to make a script which I can put in the workspace / inside models that will make them regenrate to their original form after 50% or a specific number of parts are missing from it. I tried making this code, For some reason it's not working.
for i, part in pairs(script.Parent:GetDescendants()) do if part:IsA("BasePart") then parts = parts + 1 end end if parts <= 500 then print("regenrating") end
Thanks!
Currently your script only runs at the beginning of the game. You need to check whenever a child is removed. To do that, you'd use child removed:
script.Parent.ChildRemoved:Connect(function(instance) local parts = 0 --counts up num parts for i, part in pairs(script.Parent:GetDescendants()) do if part:IsA("BasePart") then parts = parts + 1 end end --check if we need to regen if(parts <= 500)then print("Regenerating model...") --regen model here. end end