Clearing Debris

So im working on a car crashing game, and i was wondering, how can I make it so all those loose parts with no joints can disappear after a certain amount of time, but I dont want it to just clear unanchored parts because the Jeep is all unanchored, I just want it to clear parts that are Unanchored + Have no joints. so could anybody help that would be appreciated :smiley:

Using Debis (game:GetService('Debris'), you can achieve exactly that.

local Part = Instance.new('Part', workspace)

game:GetService('Debris'):AddItem(Part, 9) -- Instance, Lifetime (Seconds)
1 Like

Place .Touched events inside parts likely to be hit, once hit compare it with the 1st parameter which gives you the collided object and see if it was another car, wait a certain amount of time, destroy the model and disconnect the event.

1 Like

I donโ€™t understand

(30 chars 30 chars yes yes)

Basically there is a service called Debris and itโ€™s used to help clear I guess you could say any loose parts in workspace.

You get the service like this

local Debris = game:GetService("Debris") -- Getting the service "Debris"
local part = game.Workspace.Part -- part we want to get rid of

Debris:AddItem(part, 2) -- After two seconds the part will be gone.

AddItem is the event used by Debris to insert an item into the Debris.
The first agrument is the object, the second one is the length of time until itโ€™s removed.

2 Likes

You could put a script inside the wall that breaks the joints of anything it touches, and then use Debris:AddItem() to remove it after a certain amount of time:

local Debris = game:GetService("Debris")
local wall = script.Parent --assuming that this script is parented under the wall

wall.Touched:Connect(function(hitPart) --hitPart represents the part that touched the wall
	hitPart:BreakJoints() --detaches the part from anything it was previously welded/joined to
	Debris:AddItem(hitPart, 5) --after 5 seconds, the part will disappear.
end)
2 Likes

ohh thanks.

(30 chars poopy man)

1 Like