Sync CreateObject for all players

How do I make the native “CreateObject” sync for all players so everyone sees what I’ve spawned?

bit of my code:

RegisterNetEvent('trashcan')
AddEventHandler('trashcan', function()
    if not ( IsPedSittingInAnyVehicle( GetPlayerPed(-1) ) ) then 
        local vehicle = GetVehiclePedIsIn( GetPlayerPed(-1), true )
		local player = GetPlayerPed(-1)
		
		if (DoesEntityExist(player) and not IsEntityDead(player)) then 
			if closetotruck == true then
				SetEntityAsMissionEntity(vehicle)
				if DoesVehicleHaveDoor(vehicle, 5) then
					SetVehicleDoorOpen(vehicle, 5, false, false)
				end
				RequestModel(GetHashKey("prop_bin_10a"))
				Wait(100)
	
				trashcan = CreateObject(GetHashKey("prop_bin_10a"), GetEntityCoords(GetPlayerPed(-1)))
			end
		end
	end
end)

There’s a bool after coords called isNetwork, set it to true

For more info see https://runtime.fivem.net/doc/natives/#_0x509D5878EB39E842

2 Likes

Omg how would I not notice that… Thanks :joy:

1 Like