Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a model regenrate after amount of parts missing from it?

Asked by
Araxon 0
5 years ago
Edited 5 years ago

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!

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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
Ad

Answer this question