Server Crashes when entering vehicle


function GM.SpawnVehicle ( Player, vehicleID, paintJob )
	Player.lastVehicleSpawn = Player.lastVehicleSpawn or 0;
	if (Player.lastVehicleSpawn > CurTime()) then return; end
	Player.lastVehicleSpawn = CurTime() + 1;

	local placeToSpawn = selectVehicleSpawn(Player, vehicleID);
	
	if (!placeToSpawn) then
		Player:Notify("There was an error spawning your vehicle. Please try again later.");
		return;
	end
	
--	Player:RemoveCar();
	--for k, v in pairs(player.GetAll()) do
		--umsg.Start("removebadid", Player)
			--umsg.Short(Player:GetCarUsed());		// Fuel Left
		--umsg.End()
	--end
-- Removed, tested to see if crashing would fix/if crash was because of fuel mod
			
	local vehicleTable = VEHICLE_DATABASE[vehicleID];
	
	--Fuel
	
	-- Player:Notify(""..Player:GetLastCar().."");
	if vehicleTable.DF then
		local NewCar = vehicleTable.FID;
		if Player:GetLastCar() == 0 or Player:GetLastCar() == nil then Car = tostring(a) end;
		Car = VEHICLE_DATABASE[Player:GetLastCar()];
		local FuelToSave = Player:GetFuel();
		Player:Notify(""..FuelToSave.." "..NewCar.."");
		local ID = tonumber(Player:UniqueID());
		tmysql.query("SELECT `1` FROM `fuel` WHERE `uid`='"..ID.."' LIMIT 1", function ( test )
			if (!test || !test[1]) then
				tmysql.query("INSERT INTO `fuel` (`uid`) VALUES ('" .. tonumber(Player:UniqueID()) .. "')")
			end
		end)
		tmysql.query("UPDATE `fuel` SET `"..Car.FID.."`='"..FuelToSave.."' WHERE `uid`='"..ID.."'");
		tmysql.query("SELECT `"..NewCar.."` FROM `fuel` WHERE `uid`='"..ID.."' LIMIT 1", function ( car )
		if car[1][1] then
		Player:SetFuel(tonumber(car[1][1]))
		end
		if Player:GetFuel() == 0 then Player:SetFuel(tonumber(300)); end
		Player:Notify(""..Player:GetFuel().."");
		umsg.Start("send_fuel", Player)
			umsg.Long(tonumber(car[1][1]));		// Fuel Left
		umsg.End();
		end)
	end

	
	local vehicleTable = VEHICLE_DATABASE[vehicleID];
	local paintJobS = vehicleTable.PaintJobs[paintJob[1]];
		
	local newVehicle = ents.Create("prop_vehicle_jeep");
		newVehicle:SetModel(paintJobS.model);
		newVehicle:SetSkin(paintJobS.skin);
		newVehicle:SetPos(placeToSpawn[2]);
		newVehicle:SetAngles(placeToSpawn[3] - Angle(0, 90, 0));
		newVehicle:SetKeyValue("vehiclescript", "scripts/vehicles/_" .. vehicleTable.Script .. ".txt");
	newVehicle:Spawn();
		
	if (vehicleTable.CustomBodyGroup) then
		newVehicle:Fire("setbodygroup", tostring(vehicleTable.CustomBodyGroup), 0);
	end
	
	newVehicle.CarDamage = 50;
	newVehicle.owner = Player;
	
	newVehicle:Fire("lock", "", 0);
	
	newVehicle:SetNetworkedEntity("owner", Player);
	local ID1 = math.random(1, 32);
	local ID2 = math.random(0, 76);
	local ID3 = math.random(0, 7);

	IDString = (""..ID1..""..ID2..""..ID3.."");
	
	newVehicle.CarDamage = 50;
	newVehicle.owner = Player;	
	newVehicle:Fire("lock", "", 0);
	CarID = tostring(vehicleTable.FID)
	
	newVehicle:SetNetworkedEntity("owner", Player);
	newVehicle:SetNetworkedInt("carid", IDString);
	Player:SetCarUsed(tonumber(newVehicle:GetNetworkedInt("carid")));
		
	ID = newVehicle:GetNetworkedInt("carid")
	
	
	umsg.Start("sendcarid", Player)
		umsg.Long(tonumber(ID));
	umsg.End();
	
	Player.currentVehicle = newVehicle;
	
	newVehicle.vehicleTable = vehicleTable;
	DF = vehicleTable.DF;
	if !DF then Player:Notify("false") end
		
	if DF then Player:SetPrivateInt("lastcar", vehicleTable.ID) end;
	if DF then Player:SetPrivateInt("lastcarf", vehicleTable.FID) end;
	
	// Make passenger seats
	newVehicle.PassengerSeats = {};
	if (vehicleTable.PassengerSeats) then
		for k, v in pairs(vehicleTable.PassengerSeats) do
			CreatePassengerSeat(newVehicle, v[1], v[2]);
		end
	end
	
	newVehicle.headLightColor = paintJob[2];
	
	// Add light controller
	newVehicle.lightManager = ents.Create("ent_light_manager");
		newVehicle.lightManager:SetPos(newVehicle:LocalToWorld(newVehicle:OBBCenter()) + newVehicle:GetForward() * 100 + newVehicle:GetUp() * 10);
		newVehicle.lightManager:SetColor(HEADLIGHT_COLORS[newVehicle.headLightColor][1].r, HEADLIGHT_COLORS[newVehicle.headLightColor][1].g, HEADLIGHT_COLORS[newVehicle.headLightColor][1].b, 255);
	newVehicle.lightManager:Spawn();
	
	newVehicle.lightManager_Rear = ents.Create("ent_light_manager_rear");
		newVehicle.lightManager_Rear:SetPos(newVehicle:LocalToWorld(newVehicle:OBBCenter()) - newVehicle:GetForward() * 100 + newVehicle:GetUp() * 10);
	newVehicle.lightManager_Rear:Spawn();
	
	newVehicle.lightManager:SetParent(newVehicle);
	newVehicle.lightManager_Rear:SetParent(newVehicle);
				
	return newVehicle;
end

I have no clue where the error is occuring, so if you can skim through, would be nice.

I had thought it would be with the fuel mod, since I just made it, but I disabled it and it still crashed… This time right when I pressed e on the car to get inside, it instantly crashed.

Perp vehicles much?

Try adding in some debug stuff, like add print( “line whatever” ) in several places throughout the code, look in your servers console and see what prints and what doesn’t, then you know that what’s crashing it lies between line x and line y.

linux server?

Thank you, :D… one sec

@Muller, No.

any update on this

Hrm, I haven’t been able to solve it.

Probably because I just left it and kinda am gonna implement a new system :confused: