Game crashes with engine error?

Any idea why this code causes the game to crash? It worked before I added the vehicles but I dont see anything wrong with them and the error I am getting is !weapons.Register. This code is located in an autorun file.

if SERVER then

vehicles = {
vehiclespawns = {
Vector(150, 150, 128),
Vector(-150, 150, 128),
Vector(150, -150, 128),
Vector(-150, -150, 128)

weapons = {
weaponspawns = {
Vector(15, 15, 128),
Vector(-15, 15, 128),
Vector(15, -15, 128),
Vector(-15, -15, 128)

concommand.Add( "fieldserver", function( ply, cmd, args )

for i=1,4 do 
local vehicle = ents.Create( table.Random(vehicles) )
vehicle:SetPos( table.Random(vehiclespawns) )

local weapon = ents.Create( table.Random(weapons) )
weapon:SetPos( table.Random(weaponspawns) )


EDIT: Recoded it and somehow got it to work, although its telling me (Attempted to create unknown entity type vehicle class here!) even tho I can find them in my spawnlist.

That error means that the function weapons.Register doesn’t exist in Lua when the SWEPs are about to load.

Usually caused by Lua error from editing game files ( you should never do this ) or addons that override said files ( you should never do that either )

it’s because he’s making a global weapons table in that code

Stop creating global variables in first place
Your vehicles might not been working since most vehicles spawns prop_vehixle_jeep and then apply it script, those names are intended to name the vehicle in list.Add iirc

Don’t use table.Random also.
Use tabname[math.random(#tabname)]