# Transfer Ownership

Transfer vehicle ownership between players using a single export. Note that this is server-sided only.

***

{% hint style="info" %}
For advanced use cases where you need to pass custom vehicle data, target a specific garage, or initialize an unowned vehicle, use the [SetNewOwner](https://docs.zykeresources.com/paid-resources/garages/exports-and-events/..#set-new-owner-1) export directly. See the Exports page for details.
{% endhint %}

### Quick Start

```lua
local success, reason = exports.zyke_garages:TransferOwnership(
    "ABC 1234",      -- plate
    "char1:abc123"   -- new owner's identifier (citizenid for QB, identifier for ESX)
)
```

The script resolves the plate to a VIN internally, validates that the vehicle isn't impounded, transfers ownership, rotates keys, and assigns a valid garage — all in one call.

***

### Parameters

| Parameter  | Type     | Description                                                        |
| ---------- | -------- | ------------------------------------------------------------------ |
| `plate`    | `string` | The vehicle's license plate                                        |
| `newOwner` | `string` | Target character identifier (citizenid for QB, identifier for ESX) |

**Returns:** `boolean`, `string?` - success, failure reason

***

### Failure Reasons

| Reason                  | Meaning                                |
| ----------------------- | -------------------------------------- |
| `"missingArguments"`    | `plate` or `newOwner` was not provided |
| `"noVehicleFound"`      | No vehicle found with that plate       |
| `"vehicleIsImpounded2"` | Vehicle is currently impounded         |
| `"noPlayer"`            | Target identifier is invalid           |

***

### Example: Vehicle Dealership

```lua
RegisterNetEvent("myDealership:purchaseVehicle", function(plate)
    local source = source
    local identifier = Z.getIdentifier(source)

    local success, reason = exports.zyke_garages:TransferOwnership(plate, identifier)

    if success then
        TriggerClientEvent("myDealership:purchaseComplete", source)
    else
        print("Transfer failed: " .. (reason or "unknown"))
    end
end)
```

### Example: Admin Command

```lua
RegisterCommand("transferveh", function(source, args)
    local plate = args[1]
    local targetId = tonumber(args[2])
    if (not plate or not targetId) then return end

    local targetIdentifier = Z.getIdentifier(targetId)
    local success, reason = exports.zyke_garages:TransferOwnership(plate, targetIdentifier)

    print(success and "Transfer complete" or ("Failed: " .. (reason or "unknown")))
end, true)
```
