Script that loops through models not locating the right thing

I have a script that loops through a model and replaces scripts with newer ones. I keep getting an error though that states that DriveSeat is not a valid member of part.

The script is:

local cars = game.ServerStorage:WaitForChild("cars"):GetChildren()

for i = 1,#cars do
	local oldPickup = cars[i].DriveSeat.Pickup

	if oldPickup ~= nil then 

	local newPickup = script.Pickup:Clone()
	newPickup.Parent = cars[i].DriveSeat

	local oldDrive = cars[i]:FindFirstChild("A-Chassis Tune"):FindFirstChild("A-Chassis Interface").Drive

	if oldDrive ~= nil then 

	local newDrive = script.Drive:Clone()
	newDrive.Parent = cars[i]:FindFirstChild("A-Chassis Tune"):FindFirstChild("A-Chassis Interface")

	print("Car should have new files")


And the error is:

DriveSeat is not a valid member of Part

I’m unsure as to why I’m getting this error because if you look at the path of where the script is located, to me it seems to look ok and is the same for every model.

Thank you for any help…

Try looping through all descendants

local cars =  game.ServerStorage:WaitForChild("cars")

for _, s in ipairs(cars:GetDescendants()) do
    if s:IsA("Script") then 

or just wrap yours where you index DriveSeat in a pcall, the thing might not exist.

Why do you need to do this though? You could just use an alternate method to disable all scripts or not have them in the first place

Try printing the name of the car. It’s very likely you are accidentally including a model you don’t want to include. Or else one of the cars doesn’t have a driver’s seat.

1 Like