FindFirstVehicle, FindNextVehicle, EndFindVehicle

Here is my GetVehicles function :

function GetVehicles()

	local vehicles        = {}
	local handle, vehicle = FindFirstVehicle()
	local success         = nil

	repeat
		table.insert(vehicles, vehicle)
		success, vehicle = FindNextVehicle(handle)
	until not success

	EndFindVehicle(handle)

	return vehicles

end

Sometimes it works as expected (it returns an array with vehicles) and sometimes it returns an array with 0 as only element.

For me it works great until i restart game many times without quitting fivem (first times it returns vehicles and after {0})

For some people it returns always {0}

What am I doing wrong with these natives ?

Check this:

Thank you for the reply but both methods fail.
I really don’t understand what is going on…

weird I am using the one I linked and it is working like a charm

Maybe I have a script who screw up everything. Thank you !

I can confirm this when I disable all my scripts it works as expected.

1 Like