Roblox · Обби · урок 6

Телепорты и публикация

Портал, который переносит игрока в другую часть карты, финальная доводка и публикация игры, чтобы в неё можно было позвать друзей.

Структура

Синим — что добавляем на этом уроке.

Workspace
├─ Teleport1 (Model)
│  ├─ Ring (UnionOperation) — рамка
│  └─ Glass (Part) — CanCollide выкл., Front — вперёд
│     └─ TeleportScript (Script)
└─ Teleport2 (Model)
   ├─ Ring (UnionOperation)
   └─ Glass (Part) — Front — куда выйти

Шаги

  1. Рамка: цилиндр (Part → Shape Cylinder) и цилиндр поменьше внутри. Меньший — Model → Negate, выдели оба → Union. Получится кольцо «Ring».
  2. В кольцо — тонкий диск «Glass»: Material Glass или Neon, Transparency 0.4, CanCollide выкл., Anchored вкл.
  3. Ring + Glass → Group (Ctrl+G) → модель «Teleport1». Копия — «Teleport2» в другом месте карты.
  4. В Glass первого портала — Script «TeleportScript». TARGET — имя портала, куда ведёт.
  5. Игрок выходит в 5 studs перед вторым порталом — по его передней грани (Front). Поверни Teleport2 лицом туда, куда игрок пойдёт дальше.
  6. Нужен обратный путь — положи такой же скрипт во второй портал с TARGET = "Teleport1". Атрибут Teleported не даёт бросать игрока туда-обратно.
  7. Публикация: File → Publish to Roblox → название, описание, жанр Obby. Потом Game Settings → Permissions → Public.
  8. Game Settings → Basic Info: иконка и картинки. На create.roblox.com можно сменить их позже.

Скрипты

TeleportScript

Где: Workspace → Teleport1 → Glass · Script
Зачем: Переносит игрока ко второму порталу.

-- стекло портала
local glass = script.Parent
-- куда ведёт: имя второго портала в Workspace
local TARGET = "Teleport2"
-- стекло второго портала
local target = workspace:WaitForChild(TARGET):WaitForChild("Glass")

-- касание
glass.Touched:Connect(function(hit)
    -- модель персонажа
    local character = hit.Parent
    -- это не персонаж — выходим
    if not character:FindFirstChildOfClass("Humanoid") then return end
    -- когда телепортировался в прошлый раз
    local last = character:GetAttribute("Teleported") or 0
    -- меньше 2 секунд назад — не бросаем обратно
    if os.clock() - last < 2 then return end
    -- запоминаем время
    character:SetAttribute("Teleported", os.clock())
    -- ставим в 5 studs перед вторым порталом
    character:PivotTo(target.CFrame + target.CFrame.LookVector * 5)
-- конец функции
end)

Проверка

Запусти Play (или Run) и убедись:

Roblox · Obby · lesson 6

Teleports and publishing

A portal that moves the player to another part of the map, final touches and publishing the game so you can invite friends.

Structure

Blue — what we add in this lesson.

Workspace
├─ Teleport1 (Model)
│  ├─ Ring (UnionOperation) — the frame
│  └─ Glass (Part) — CanCollide off, Front facing forward
│     └─ TeleportScript (Script)
└─ Teleport2 (Model)
   ├─ Ring (UnionOperation)
   └─ Glass (Part) — Front — where to come out

Steps

  1. Frame: a cylinder (Part → Shape Cylinder) and a smaller cylinder inside it. The smaller one — Model → Negate, select both → Union. You get a ring "Ring".
  2. Inside the ring put a thin disc "Glass": Material Glass or Neon, Transparency 0.4, CanCollide off, Anchored on.
  3. Ring + Glass → Group (Ctrl+G) → a model "Teleport1". A copy — "Teleport2" somewhere else on the map.
  4. In the first portal's Glass put a Script "TeleportScript". TARGET is the name of the portal it leads to.
  5. The player comes out 5 studs in front of the second portal — along its front face (Front). Turn Teleport2 to face where the player goes next.
  6. Need a way back? Put the same script into the second portal with TARGET = "Teleport1". The Teleported attribute stops the player bouncing back and forth.
  7. Publishing: File → Publish to Roblox → name, description, genre Obby. Then Game Settings → Permissions → Public.
  8. Game Settings → Basic Info: the icon and images. You can change them later on create.roblox.com.

Scripts

TeleportScript

Where: Workspace → Teleport1 → Glass · Script
Why: Moves the player to the second portal.

-- the portal glass
local glass = script.Parent
-- where it leads: the second portal's name in Workspace
local TARGET = "Teleport2"
-- the second portal's glass
local target = workspace:WaitForChild(TARGET):WaitForChild("Glass")

-- touch
glass.Touched:Connect(function(hit)
    -- the character model
    local character = hit.Parent
    -- not a character — exit
    if not character:FindFirstChildOfClass("Humanoid") then return end
    -- when it last teleported
    local last = character:GetAttribute("Teleported") or 0
    -- less than 2 seconds ago — don't send back
    if os.clock() - last < 2 then return end
    -- remember the time
    character:SetAttribute("Teleported", os.clock())
    -- place 5 studs in front of the second portal
    character:PivotTo(target.CFrame + target.CFrame.LookVector * 5)
-- end of function
end)

Testing

Press Play (or Run) and make sure: