Trying to get children with InPairs

I’ve been trying to get some of my properties with the names, “SuspensionFL”, “SuspensionFR”, “SuspensionRL”, and “SuspensionRR” and I’ve tried everything and I need some help really badly for this

What it looks like:
Screen Shot 2021-06-03 at 8.30.21 PM

Program:

wheels = {}
touchingparts = {}

for _, Child in pairs(script.Parent:GetChildren()) do
	 table.insert(wheels, script.Parent:FindFirstChild("SuspensionFL"), script.Parent:FindFirstChild("SuspensionFR"), script.Parent:FindFirstChild("SuspensionRL"), script.Parent:FindFirstChild("SuspensionRR"))
end

print(wheels)
print(touchingparts)

for i, v in pairs(wheels) do 
	wheels.Touched:connect(function(part)
		print(part)
		script.Material.Value = part.Material 
		script.Color.Value = part.Color
	end)
end
1 Like

just remove the Inpairs function and it should work.

What kind of answer is that???

1 Like

Your using table.insert incorrectly, table.insert only uses 3 arguments as table to insert to, index of object and the object itself. To do this correctly you would need to insert the “v” value from the inpairs to table.insert.

for i,v in pairs(script.Parent:GetChildren()) do
   table.insert(wheels,v)
end

What I mean by that is the fact you are trying to insert it inside of an InPairs function meaning it would not only insert multiple times, but as @Wizard101fire90 said, you only need 3 arguments in the table and don’t insert multiple at a time. There are multiple ways to do this, such as:

table.insert(wheels, script.Parent:FindFirstChild("SuspensionFL")
table.insert(wheels, script.Parent:FindFirstChild("SuspensionFR"))
table.insert(wheels, script.Parent:FindFirstChild("SuspensionRL"))
table.insert(wheels, script.Parent:FindFirstChild("SuspensionRR"))

or this:

for _,Child in pairs(script.Parent:GetChildren()) do
	if Child:IsA("Model") and string.find(Child.Name, "Suspension") then
		table.insert(wheels, Child)
	end
end

or, you could have it already in the table like this:

wheels = {
	["SuspensionFL"] = script.Parent:FindFirstChild("SuspensionFL"),
	["SuspensionFR"] = script.Parent:FindFirstChild("SuspensionFR"),
	["SuspensionRL"] = script.Parent:FindFirstChild("SuspensionRL"),
	["SuspensionRR"] = script.Parent:FindFirstChild("SuspensionRR")
}
1 Like