Roblox · Обби · урок 2
Первые скрипты: блок, который убивает при касании, и блок, который разгоняет игрока. Это основа почти всех ловушек в обби.
Синим — что добавляем на этом уроке.
Workspace ├─ KillBrick (Part) — красный, Material Neon │ └─ KillScript (Script) ├─ SpeedBrick (Part) — зелёный │ └─ SpeedScript (Script) └─ NormalBrick (Part) — возвращает скорость └─ NormalSpeedScript (Script)
Где: Workspace → KillBrick · Script
Зачем: Убивает игрока при касании.
-- деталь, в которой лежит скрипт
local part = script.Parent
-- когда что-то касается детали
part.Touched:Connect(function(hit)
-- Humanoid есть только у персонажей
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
-- коснулся персонаж
if humanoid then
-- здоровье в ноль — игрок погибает
humanoid.Health = 0
-- конец проверки
end
-- конец функции
end)Где: Workspace → SpeedBrick · Script
Зачем: Разгоняет игрока до 25.
-- деталь со скриптом
local part = script.Parent
-- новая скорость; обычная — 16
local SPEED = 25
-- касание
part.Touched:Connect(function(hit)
-- ищем Humanoid
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
-- это персонаж
if humanoid then
-- меняем скорость ходьбы
humanoid.WalkSpeed = SPEED
-- конец проверки
end
-- конец функции
end)Где: Workspace → NormalBrick · Script
Зачем: Возвращает обычную скорость 16.
-- деталь со скриптом
local part = script.Parent
-- обычная скорость Roblox
local SPEED = 16
-- касание
part.Touched:Connect(function(hit)
-- ищем Humanoid
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
-- это персонаж
if humanoid then
-- меняем скорость ходьбы
humanoid.WalkSpeed = SPEED
-- конец проверки
end
-- конец функции
end)Запусти Play (или Run) и убедись:
Roblox · Obby · lesson 2
First scripts: a block that kills on touch and a block that speeds the player up. These are the basis of almost every obby trap.
Blue — what we add in this lesson.
Workspace ├─ KillBrick (Part) — red, Material Neon │ └─ KillScript (Script) ├─ SpeedBrick (Part) — green │ └─ SpeedScript (Script) └─ NormalBrick (Part) — restores speed └─ NormalSpeedScript (Script)
Where: Workspace → KillBrick · Script
Why: Kills the player on touch.
-- the part that holds the script
local part = script.Parent
-- when something touches the part
part.Touched:Connect(function(hit)
-- only characters have a Humanoid
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
-- a character touched it
if humanoid then
-- health to zero — the player dies
humanoid.Health = 0
-- end of check
end
-- end of function
end)Where: Workspace → SpeedBrick · Script
Why: Speeds the player up to 25.
-- the part with the script
local part = script.Parent
-- the new speed; normal is 16
local SPEED = 25
-- touch
part.Touched:Connect(function(hit)
-- look for a Humanoid
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
-- it's a character
if humanoid then
-- change the walking speed
humanoid.WalkSpeed = SPEED
-- end of check
end
-- end of function
end)Where: Workspace → NormalBrick · Script
Why: Restores the normal speed of 16.
-- the part with the script
local part = script.Parent
-- the normal Roblox speed
local SPEED = 16
-- touch
part.Touched:Connect(function(hit)
-- look for a Humanoid
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
-- it's a character
if humanoid then
-- change the walking speed
humanoid.WalkSpeed = SPEED
-- end of check
end
-- end of function
end)Press Play (or Run) and make sure: