Check if model exist without error's in script

This post might feel like all the other post talking about this, however my issue is different and can’t fix it. Even with some of the other forums help.

What is the issue? Include screenshots / videos if possible!
In my game I have a car spawner where you can pick all types of cars, and I have a button for checking it’s info such as (Seats), (Speed), (Color), (Brand), (Model) Etc.

The issues stems when you join the game, and because I have over 400 cars/vehicles the scripts will error out if any cars are missing from a folder instead of warning in the output.

Error: Cars is not a valid member of ServerStorage “ServerStorage”

local VehicleSeats = game.ServerStorage.Cars:FindFirstChild("Ford_LTD_Wagon")--Read here: yes this part of the code errors out because of the way it's writen, trying to find a different way.
local NOS = script.Parent.NumOfSeats
local TS = script.Parent.TopSpeed

if not VehicleSeats then
	warn(script.Parent.Brand.Value.." "..script.Parent.Model.Value..": doesn't exist. Either the Car/Vehicle is: (Missing) (Deleted) or (Misspelled)")
else
	for I, GetAllSeats in pairs(VehicleSeats:GetDescendants()) do
		if GetAllSeats:IsA("Seat") then
			NOS.Value = NOS.Value + 1
		end
	end
	TS.Value = VehicleSeats.VehicleSeat.MaxSpeed
	NOS.Value = NOS.Value + 1
end

wait(5)
script:Destroy()--this just gets rid of the code as it isn't needed once you join in

Please do not write entire scripts or design entire systems for meh.

3 Likes

Is the script on client or server?

The server script is just stored inside a folder like this.

Try this

local VehicleSeats = game.ServerStorage:WaitForChild("Cars"):FindFirstChild("Ford_LTD_Wagon")
1 Like

it did nothing and it’s still the same thing

actually it says this:
17:22:03.147 Stack Begin - Studio
17:22:03.147 Script ‘Players.cookpie416.PlayerGui.New_CarSpawner_V2.Other_Frame.Real_Life_Cars.CarArea.Ford.CarSectionDD.Vehicle_Info_Values_Folder.Auto_Apply_Info’, Line 5 - Studio - Auto_Apply_Info:5
17:22:03.147 Stack End - Studio

Maybe try to move the Car model to ReplicatedStorage, and replace ServerStorage to game.ReplicatedStorage

The cars have to be in ServerStorage and can’t be anywhere else

local VehicleSeats = game.ServerStorage:FindFirstChild("Cars") and game.ServerStorage.Cars:FindFirstChild("Ford_LTD_Wagon")--Read here: yes this part of the code errors out because of the way it's writen, trying to find a different way.
local NOS = script.Parent.NumOfSeats
local TS = script.Parent.TopSpeed

if not VehicleSeats then
	warn(script.Parent.Brand.Value.." "..script.Parent.Model.Value..": doesn't exist. Either the Car/Vehicle is: (Missing) (Deleted) or (Misspelled)")
else
	for I, GetAllSeats in pairs(VehicleSeats:GetDescendants()) do
		if GetAllSeats:IsA("Seat") then
			NOS.Value = NOS.Value + 1
		end
	end
	TS.Value = VehicleSeats.VehicleSeat.MaxSpeed
	NOS.Value = NOS.Value + 1
end

wait(5)
script:Destroy()--this just gets rid of the code as it isn't needed once you join in

this code will make VehicleSeats return nil if the cars folder doesn’t exist

3 Likes

thanks for the fix to the code.

Rarde ALC Wagon: doesn’t exist. Either the Car/Vehicle is: (Missing) (Deleted) or (Misspelled) :grinning:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.