RegisterNetEvent('spawncar') local eventData = AddEventHandler('spawncar', function(model) local hash = GetHashKey(model) Citizen.CreateThread(function() RequestModel(hash) while not HasModelLoaded(hash) do Citizen.Wait(0) end end,false) local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), false)) local vehicle = CreateVehicle(hash, x + 2, y + 2, z + 1, 0.0, true, false) end)
RegisterCommand('createcar', function(source,args,rawCommand) if args == nil then print("Error you have not typed in the name of the vehicle you're trying to spawn!") else TriggerClientEvent('spawncar', source , *args) end end, false)
My goal: CreateVehicle returns 0 if there is no such model to be spawned. I want to handle that as an error and print out an message. Only issue is that print only seems to work on server script. My idea was making an pointer at first to modify args then handle the error from there, but from what I googled there’s no such option for this. How do people handle error printing if code is executed on client side? ( I didn’t manage to find a post about this so I apologize if there’s an thread about this already, cheers! )
Edit: By error handling I mean this:
if vehicle == nil then print("Vehicle model you're trying to spawn doesn't exist") else print("You have spawned " ... vehicle ... "!") end
I think this explains it enough.