Wondering how to network my plane

this creates how ever many planes as their is players in the city

function createHeli()
    local vehicle = GetHashKey('dodo')
    local hPed = GetHashKey("s_m_y_pilot_01")
    RequestModel(vehicle)
    while not HasModelLoaded(vehicle) do
        Wait(1)
    end
    RequestModel(GetHashKey("s_m_y_pilot_01"))
    while not HasModelLoaded(GetHashKey("s_m_y_pilot_01")) do
      Wait(1)
    end
    local cluttered = GetClosestVehicle(2340.255859375, 6687.5219726563, 516.81469726563, 25.0, 0, 16384)
    local pos = GetEntityCoords(GetPlayerPed(-1), true)
    if not DoesEntityExist(existingVeh) then
    	Citizen.Trace("Plane has spawned")
	    existingVeh = CreateVehicle(vehicle, 2340.255859375, 6687.5219726563, 516.81469726563, 73.0, true, false)
		heliPilot = CreatePedInsideVehicle(existingVeh, 4, GetHashKey("s_m_y_pilot_01"), -1, 1, true)

wondering how I can just get it to spawn once and only one, I can’t figure it out :confused:

On the client:

When player spawns...
triggerserverevent to spawn plane

On server:

local planespawned = false

Receive event to spawn plane:
if planespawned = false, then triggerclientevent to spawn
set planespawned = true

Then just have it trigger on the client the function you posted. You’ll need the server side variable so it only spawns for the first trigger.

1 Like