I have a race game and the car pieces can fall off when the car takes damage. I need help with how to detect welds

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A car has Important components like the engine, the vehicleseat and the chassis and the fueltank etc…

I need a function that checks if a basepart called “engine” is connected to a part connected to a part connected to a part etc until it reaches the part called “Fueltank” or “Battery”
Ideally I think it should use “GetJoints()”

  1. What is the issue? Include screenshots / videos if possible!

Cars can drive even with the fueltank and the engine unwelded yet in the same model.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I learned the :GetJoints() is useful but not useful enough.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local function CarCheck(Car)
	for i,v in pairs(Car:GetDescendants()) do
		if v:IsA("BasePart") then 
			if v:GetJoints() == nil then
				
				v.Parent = game.Workspace
				end
		end
	end
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

JointInstances have a Part0 and Part1 property that you can use to see what parts are connected. You can do what you want by writing a recursive function that gets the joints of a part and goes through any connected parts.

Yeah but how do I do the recursive?

Do I use repeat until?

Recursive means that the function can call itself.

So I did some searching and there is actually a much simpler way to do this using BasePart:GetConnectedParts(). You should be able to do Engine:GetConnectedParts(true) to get all the parts connected to the engine, then check if the Fueltank or Battery is one of those parts.

Yeah but sometimes there can be parts in between these parts which connect both of them…

How do I loop through those parts without causing my game to crash?

BasePart:GetConnectedParts(true) will get all attached parts, even if they are not directly connected.
If you want only directly connected parts you can just do BasePart:GetConnectedParts()

<3

You get 100 bonus coins in my race game.