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:
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
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:
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: