Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.