Roblox · Обби · урок 3
Три новых препятствия: ступени, которые растворяются под ногами, платформа, которая возит игрока, и лента-конвейер, против которой надо бежать.
Синим — что добавляем на этом уроке.
Workspace ├─ Stairs (Folder) │ └─ Step (Part) — жёлтая ступенька │ └─ DisappearScript (Script) ├─ MovingPlatform (Part) — передняя грань (Front) — куда ехать │ └─ MoveScript (Script) └─ Conveyor (Part) — Anchored вкл. └─ ConveyorScript (Script)
Где: Workspace → Stairs → Step · Script
Зачем: Ступень растворяется и через 2 секунды возвращается.
-- ступенька
local part = script.Parent
-- ступень уже исчезает — повторные касания не считаем
local busy = false
-- касание
part.Touched:Connect(function(hit)
-- уже исчезает — выходим
if busy then return end
-- исчезает только от игрока
if not hit.Parent:FindFirstChildOfClass("Humanoid") then return end
-- занято
busy = true
-- 20 шагов
for i = 1, 20 do
-- с каждым шагом прозрачнее
part.Transparency = i / 20
-- всего за 1 секунду
task.wait(0.05)
-- конец цикла
end
-- сквозь ступень можно упасть
part.CanCollide = false
-- 2 секунды её нет
task.wait(2)
-- снова видна
part.Transparency = 0
-- снова твёрдая
part.CanCollide = true
-- готова к следующему игроку
busy = false
-- конец функции
end)Где: Workspace → MovingPlatform · Script
Зачем: Возит платформу туда-обратно.
-- платформа
local platform = script.Parent
-- сколько studs проезжает
local DISTANCE = 14
-- за сколько секунд
local TIME = 3
-- откуда
local start = platform.Position
-- куда: вперёд по передней грани (Front)
local finish = start + platform.CFrame.LookVector * DISTANCE
-- точка, за которую тянем
local attachment = Instance.new("Attachment")
-- в центре платформы
attachment.Parent = platform
-- сила, которая тянет деталь в точку
local align = Instance.new("AlignPosition")
-- тянем к координате, а не к другой детали
align.Mode = Enum.PositionAlignmentMode.OneAttachment
-- кого тянем
align.Attachment0 = attachment
-- сила без предела — игрок её не остановит
align.MaxForce = math.huge
-- скорость: путь за TIME секунд
align.MaxVelocity = DISTANCE / TIME
-- быстро реагирует
align.Responsiveness = 50
-- пока стоим на месте
align.Position = start
-- в платформу
align.Parent = platform
-- держит платформу ровно
local turn = Instance.new("AlignOrientation")
-- к заданному повороту
turn.Mode = Enum.OrientationAlignmentMode.OneAttachment
-- кого держим
turn.Attachment0 = attachment
-- жёстко, без раскачки
turn.RigidityEnabled = true
-- поворот как сейчас
turn.CFrame = platform.CFrame.Rotation
-- в платформу
turn.Parent = platform
-- теперь её двигает физика — игрок едет вместе с ней
platform.Anchored = false
-- физику платформы считает сервер — без рывков
platform:SetNetworkOwner(nil)
-- бесконечно туда-обратно
while true do
-- едем вперёд
align.Position = finish
-- доехали и стоим секунду
task.wait(TIME + 1)
-- едем обратно
align.Position = start
-- доехали и стоим
task.wait(TIME + 1)
-- конец цикла
endГде: Workspace → Conveyor · Script
Зачем: Лента тащит игрока.
-- лента (Anchored вкл.)
local part = script.Parent
-- скорость ленты; игрок ходит со скоростью 16
local SPEED = 12
-- закреплённая деталь не едет, но везёт всех, кто на ней
part.AssemblyLinearVelocity = part.CFrame.LookVector * SPEEDЗапусти Play (или Run) и убедись:
Roblox · Obby · lesson 3
Three new obstacles: steps that dissolve under your feet, a platform that carries the player, and a conveyor belt you have to run against.
Blue — what we add in this lesson.
Workspace ├─ Stairs (Folder) │ └─ Step (Part) — a yellow step │ └─ DisappearScript (Script) ├─ MovingPlatform (Part) — the front face (Front) — the direction to travel │ └─ MoveScript (Script) └─ Conveyor (Part) — Anchored on └─ ConveyorScript (Script)
Where: Workspace → Stairs → Step · Script
Why: The step dissolves and comes back after 2 seconds.
-- the step
local part = script.Parent
-- the step is already vanishing — ignore repeated touches
local busy = false
-- touch
part.Touched:Connect(function(hit)
-- already vanishing — exit
if busy then return end
-- only a player makes it vanish
if not hit.Parent:FindFirstChildOfClass("Humanoid") then return end
-- busy
busy = true
-- 20 steps
for i = 1, 20 do
-- more transparent with each step
part.Transparency = i / 20
-- 1 second in total
task.wait(0.05)
-- end of loop
end
-- you can fall through the step
part.CanCollide = false
-- it's gone for 2 seconds
task.wait(2)
-- visible again
part.Transparency = 0
-- solid again
part.CanCollide = true
-- ready for the next player
busy = false
-- end of function
end)Where: Workspace → MovingPlatform · Script
Why: Moves the platform back and forth.
-- the platform
local platform = script.Parent
-- how many studs it travels
local DISTANCE = 14
-- in how many seconds
local TIME = 3
-- from
local start = platform.Position
-- to: forward along the front face (Front)
local finish = start + platform.CFrame.LookVector * DISTANCE
-- the point we pull by
local attachment = Instance.new("Attachment")
-- at the platform's center
attachment.Parent = platform
-- a force that pulls the part to a point
local align = Instance.new("AlignPosition")
-- pull toward a coordinate, not another part
align.Mode = Enum.PositionAlignmentMode.OneAttachment
-- what we pull
align.Attachment0 = attachment
-- unlimited force — a player can't stop it
align.MaxForce = math.huge
-- speed: the distance in TIME seconds
align.MaxVelocity = DISTANCE / TIME
-- responds quickly
align.Responsiveness = 50
-- stay in place for now
align.Position = start
-- into the platform
align.Parent = platform
-- keeps the platform level
local turn = Instance.new("AlignOrientation")
-- toward the set rotation
turn.Mode = Enum.OrientationAlignmentMode.OneAttachment
-- what we hold
turn.Attachment0 = attachment
-- rigid, no wobbling
turn.RigidityEnabled = true
-- the current rotation
turn.CFrame = platform.CFrame.Rotation
-- into the platform
turn.Parent = platform
-- now physics moves it — the player rides along
platform.Anchored = false
-- the server runs the platform's physics — no jerks
platform:SetNetworkOwner(nil)
-- back and forth forever
while true do
-- go forward
align.Position = finish
-- arrived, wait a second
task.wait(TIME + 1)
-- go back
align.Position = start
-- arrived, wait
task.wait(TIME + 1)
-- end of loop
endWhere: Workspace → Conveyor · Script
Why: The belt drags the player.
-- the belt (Anchored on)
local part = script.Parent
-- belt speed; the player walks at 16
local SPEED = 12
-- an anchored part doesn't move but carries everyone on it
part.AssemblyLinearVelocity = part.CFrame.LookVector * SPEEDPress Play (or Run) and make sure: