gta6/prompts
housing
Freebeginnerhousing

Instanced Apartment Enter/Exit

Walk to a door, press E, and get teleported into a private routing-bucket interior that no other player can see.

NON-TESTÉ — the reference Lua is syntax-validated, not run in a live FiveM server. Adapt and test on your own dev server before shipping.
Est. Lua
~74 loc
Claude
Claude Opus 4.x / Sonnet 4.x
Validation
syntax-validated
Updated
2026-06-24

Description

A self-contained apartment entrance: the player approaches a door marker, presses E, and is teleported into a shell interior placed in their own routing bucket so the apartment is private. Exiting resets the bucket and returns them outside. This is the foundation every multi-tenant housing or apartment script is built on — instancing is what stops twenty players from spawning in the same living room.

Prompt Template

You are writing a FiveM script for es_extended (stable, exports-based
getSharedObject). Produce ONE Lua file containing both a client and a server
section, separated by "-- ===== client.lua =====" and
"-- ===== server.lua =====" banners.

Goal: an instanced apartment.
- Entrance marker at [ENTRANCE_COORDS vector3]; interior spawn at
  [INTERIOR_COORDS vector4 (x,y,z,heading)].
- CLIENT: a CreateThread loop using PlayerPedId() and GetEntityCoords; when the
  player is within 2.0m show a help prompt and on IsControlJustReleased(0, 38)
  TriggerServerEvent("housing:enterApartment"). Add a /leaveapt command that
  fires "housing:exitApartment". Handle "housing:teleportInside" and
  "housing:teleportOutside" by fading the screen out, SetEntityCoords, then
  fading back in.
- SERVER: on "housing:enterApartment" assign a UNIQUE routing bucket per player
  with SetPlayerRoutingBucket(src, 100000 + src), then TriggerClientEvent the
  teleport. On exit reset the bucket to 0.

Requirements: register every net event on the correct side; use PlayerPedId()
not GetPlayerPed(-1); ALWAYS DoScreenFadeOut before teleporting and
DoScreenFadeIn after; ALWAYS reset the routing bucket to 0 on exit. Return only
the Lua, no prose.

Expected Output

The reference Lua at content/expected-outputs/housing/01-instanced-apartment.lua implements the proximity prompt + fade teleport on the client and the per-player routing-bucket assignment on the server. In a real resource the two banner sections become client.lua and server.lua, listed respectively as client_script and server_script in fxmanifest.lua.

01-instanced-apartment.lua74 lines
-- 01-instanced-apartment.lua
-- Enter/exit an instanced apartment using bucket-based instancing.
-- ESX (exports getSharedObject). Both sides in one file via banners.

-- ===== client.lua =====
local ESX = exports["es_extended"]:getSharedObject()

local ENTRANCE = vector3(-1289.13, -1116.85, 6.99)
local INTERIOR = vector4(266.39, -1007.55, -101.0, 180.0)
local insidePrompt = false

CreateThread(function()
    while true do
        local sleep = 1000
        local ped = PlayerPedId()
        local coords = GetEntityCoords(ped)
        if #(coords - ENTRANCE) < 2.0 then
            sleep = 0
            BeginTextCommandDisplayHelp("STRING")
            AddTextComponentSubstringPlayerName("Press ~INPUT_CONTEXT~ to enter your apartment")
            EndTextCommandDisplayHelp(0, false, true, -1)
            if IsControlJustReleased(0, 38) then
                TriggerServerEvent("housing:enterApartment")
            end
        end
        Wait(sleep)
    end
end)

-- Server teleports + assigns bucket, then tells us where to spawn.
RegisterNetEvent("housing:teleportInside", function()
    local ped = PlayerPedId()
    DoScreenFadeOut(400)
    Wait(450)
    SetEntityCoords(ped, INTERIOR.x, INTERIOR.y, INTERIOR.z, false, false, false, false)
    SetEntityHeading(ped, INTERIOR.w)
    insidePrompt = true
    Wait(200)
    DoScreenFadeIn(400)
end)

RegisterNetEvent("housing:teleportOutside", function()
    local ped = PlayerPedId()
    DoScreenFadeOut(400)
    Wait(450)
    SetEntityCoords(ped, ENTRANCE.x, ENTRANCE.y, ENTRANCE.z, false, false, false, false)
    insidePrompt = false
    Wait(200)
    DoScreenFadeIn(400)
end)

RegisterCommand("leaveapt", function()
    if insidePrompt then
        TriggerServerEvent("housing:exitApartment")
    end
end, false)

-- ===== server.lua =====
local ESXs = exports["es_extended"]:getSharedObject()

RegisterNetEvent("housing:enterApartment", function()
    local src = source
    -- One bucket per player keeps interiors private.
    local bucket = 100000 + src
    SetPlayerRoutingBucket(src, bucket)
    TriggerClientEvent("housing:teleportInside", src)
end)

RegisterNetEvent("housing:exitApartment", function()
    local src = source
    SetPlayerRoutingBucket(src, 0)
    TriggerClientEvent("housing:teleportOutside", src)
end)

Known Failure Modes

  • No instancing — Claude often teleports client-side only and skips SetPlayerRoutingBucket, so all players share one interior. Insist the bucket is assigned server-side, unique per player.
  • Teleport before fade — moving the ped before DoScreenFadeOut shows the interior streaming in. Require fade-out → WaitSetEntityCoords → fade-in.
  • Bucket never reset — forgetting SetPlayerRoutingBucket(src, 0) on exit leaves the player isolated. State the reset explicitly.

Integration Notes

  • Split the banner sections into client.lua and server.lua; declare both in fxmanifest.lua (client_script / server_script) and add es_extended as a dependency.
  • The interior coords above are a placeholder shell — point them at a real MLO or an ipl you load.
  • Test on a dev server with two connected clients: both should be unable to see each other once inside.

Profit Potential

$150–$2200/mo on Tebex (expected ~$600). [INFERRED] beginner instancing foundation scaled below the $50-389 band center against the signal-scraper tebex corpus (median seller $11.85K/mo, n=100); high demand but easy to replicate keeps standalone units modest.

Trend Signal

rising — housing systems niche-selection 3.60; corpus ox_doorlock active.

Sales Angle

Position as the routing-bucket foundation every multi-tenant housing script is built on. Recommended Tebex price $59 — a low-friction starter that funnels buyers toward your full housing suite.

Difficulty & Ship Time

beginner · ships in 2-3h.