If the money removal is now working for you then try these edits. Instead of sending all the variables to the server and back to the client again to be used in the event you could alternatively store them as local variables in the client script and have the SpawnVehicle function update them before triggering the server event.
sv_vehicles (server file)
RegisterServerEvent('spawn:moneyCheck')
AddEventHandler('spawn:moneyCheck', function (price, model, x, y, z, heading, ped)
local Source = tonumber(source)
TriggerEvent('es:getPlayerFromId', Source, function(user)
if not price then
price = 100
end
local paid = false
if user.getMoney() >= tonumber(price) then
user.removeMoney(tonumber(price))
paid = true
else
paid = false
end
TriggerClientEvent('vehPaid', source, model, x, y, z, heading, ped, paid)
end)
end)
cl_vehicles (client file)
local function SpawnVehicle(model, x, y, z, heading, ped)
-- Just in case they are in a vehicle which this trainer didn't spawn.
if not lastVehicle and GetVehiclePedIsIn(ped, false) then
lastVehicle = GetVehiclePedIsIn(ped, false)
end
cost = 100
TriggerServerEvent('spawn:moneyCheck', tonumber(cost), model, x, y, z, heading, ped)
end
RegisterNetEvent('vehPaid')
AddEventHandler('vehPaid', function(model, x, y, z, heading, ped, paid)
if not paid then
drawNotification ("~r~Not enough money!")
else
drawNotification ("~g~Payment successful.")
if IsModelValid(model) then
_LoadModel( model )
local veh = CreateVehicle( model, x, y, z + 1, heading, true, true )
if featureSpawnInsideCar then
SetPedIntoVehicle(ped, veh, -1)
end
if featureDeleteLastVehicle then
_SetEntityAsNoLongerNeeded(veh)
-- Remove the last vehicle.
if (lastVehicle) then
if(GetVehicleNumberOfPassengers(lastVehicle) ~= 0 or IsVehicleSeatFree(lastVehicle, -1) == false) then
drawNotification("~r~Last Vehicle could not be deleted.")
else
SetEntityAsMissionEntity(lastVehicle, true, true)
DeleteVehicle(lastVehicle)
end
end
end
drawNotification("~g~Vehicle spawned!")
lastVehicle = veh
UpdateVehicleFeatureVariables( veh )
toggleRadio(ped)
SetModelAsNoLongerNeeded( veh )
return veh
else
drawNotification("~r~Invalid Model!")
end
end
end)