Roblox · Обби · урок 6
Портал, который переносит игрока в другую часть карты, финальная доводка и публикация игры, чтобы в неё можно было позвать друзей.
Синим — что добавляем на этом уроке.
Workspace ├─ Teleport1 (Model) │ ├─ Ring (UnionOperation) — рамка │ └─ Glass (Part) — CanCollide выкл., Front — вперёд │ └─ TeleportScript (Script) └─ Teleport2 (Model) ├─ Ring (UnionOperation) └─ Glass (Part) — Front — куда выйти
Где: 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
A portal that moves the player to another part of the map, final touches and publishing the game so you can invite friends.
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
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)Press Play (or Run) and make sure: