Menu
CoddyTech

꼭대기에 도달하기

Coddy의 Roblox 게임: 끝없는 타워 코스 레슨. 21개 중 14번째.

타워 꼭대기의 금색 FinishPad는 올라가기를 끝내고 승리한 플레이어를 로비로 돌려보냅니다. stack은 자신이 배치한 Finish를 반환하므로, 바로 그곳에서 패드의 Touched 이벤트를 연결하세요.

Touched는 접촉한 신체 부위를 전달합니다. 그 부위의 Parent는 캐릭터이며, Players:GetPlayerFromCharacter는 해당 캐릭터의 Player를 반환하고, 그 외의 경우에는 nil을 반환합니다.

local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
	print(player.Name .. " stepped on the pad")
end

Touched는 각 신체 부위마다 한 번씩 발생하므로, 주의하지 않으면 한 번 착지했을 때 세 번이나 네 번 승리할 수 있습니다. 이번 라운드에서 완료한 플레이어를 표에 기록하고, 각 플레이어가 한 번만 승리하게 하세요.

local finished = {}

if finished[player] then
	return
end
finished[player] = true

표의 키로 Player를 사용할 수 있으므로, finished[player]는 해당 플레이어의 항목입니다. 새 라운드가 시작되면 표를 비워 모두가 다시 승리할 수 있게 하세요.

challenge icon

챌린지

중급

맨 위의 금색 패드에 도달하면 승리합니다.

  1. local lobbySpawn = workspace.Lobby.SpawnLocation과 local finished = {}를 추가하세요. startRound는 finished를 비웁니다.
  2. reachTop(hit)을 작성하세요. Players:GetPlayerFromCharacter(hit.Parent)가 아직 완료하지 않은 플레이어를 반환하지 않으면 중단하세요. 해당 플레이어를 완료한 것으로 표시하고, Wins에 1을 더한 다음, print(player.Name .. " reached the top")을 실행하고, hit.Parent를 lobbySpawn보다 4스터드 위로 이동시키세요.
  3. buildTower에서 FinishPad.Touched를 해당 함수에 연결하세요.

‘플레이’를 누르고 금색 패드에 도달하세요. 승리하고 로비에 도착합니다. 그런 다음 ‘확인’을 누르세요.

직접 해보기

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Settings = require(game.ReplicatedStorage.Settings)

local stages = ServerStorage.Stages
local tower = nil
local towerStages = {}
local lava = nil

print("Each tower has " .. Settings.StageCount .. " stages")

-- 모든 플레이어의 리더보드에 Wins가 추가됩니다
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Parent = leaderstats
end)

-- 로비에 있는 게시판
local gui = Instance.new("SurfaceGui")
gui.Parent = workspace.Lobby.Board

local boardLabel = Instance.new("TextLabel")
boardLabel.Name = "Status"
boardLabel.Size = UDim2.fromScale(1, 1)
boardLabel.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
boardLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
boardLabel.TextScaled = true
boardLabel.Text = "Endless Tower"
boardLabel.Parent = gui

local function setBoard(text)
	boardLabel.Text = text
end

-- Kill 태그가 붙은 것에 닿으면 목숨을 잃습니다
local function killOnTouch(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.Health = 0
	end
end

-- 사람이 밟으면 곧 사라졌다가 다시 나타나는 발판
local function makeVanish(part)
	part.Touched:Connect(function(hit)
		if part:GetAttribute("Gone") or not hit.Parent:FindFirstChild("Humanoid") then
			return
		end
		part:SetAttribute("Gone", true)
		task.wait(Settings.VanishDelay)
		part.Transparency = 0.8
		part.CanCollide = false
		task.wait(Settings.VanishTime)
		part.Transparency = 0
		part.CanCollide = true
		part:SetAttribute("Gone", nil)
	end)
end

-- 레이저가 Slide 오프셋까지 이동했다가 돌아오기를 계속 반복합니다
local function makeSlide(part)
	local info = TweenInfo.new(Settings.SlideTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true)
	local goal = { Position = part.Position + part:GetAttribute("Slide") }
	TweenService:Create(part, info, goal):Play()
end

-- 점프 패드는 밟은 사람을 공중으로 튕겨 올립니다
local function bounce(hit)
	local root = hit.Parent:FindFirstChild("HumanoidRootPart")
	if root then
		root.AssemblyLinearVelocity = Vector3.new(0, Settings.BouncePower, 0)
	end
end

-- 회전 장애물은 매 프레임 조금씩 회전합니다
RunService.Heartbeat:Connect(function(dt)
	for _, spinner in CollectionService:GetTagged("Spinner") do
		if spinner:IsDescendantOf(workspace) then
			spinner:PivotTo(spinner:GetPivot() * CFrame.Angles(0, math.rad(Settings.SpinSpeed) * dt, 0))
		end
	end
end)

-- 태그에 따라 스테이지의 모든 장애물을 활성화합니다
local function setupStage(stage)
	for _, part in stage:GetDescendants() do
		if part:HasTag("Kill") then
			part.Touched:Connect(killOnTouch)
		end
		if part:HasTag("Vanish") then
			makeVanish(part)
		end
		if part:HasTag("Conveyor") then
			part.AssemblyLinearVelocity = part.CFrame.LookVector * Settings.BeltSpeed
		end
		if part:HasTag("Slider") then
			makeSlide(part)
		end
		if part:HasTag("Bounce") then
			part.Touched:Connect(bounce)
		end
	end
end

-- 스테이지 하나를 무작위로 선택합니다
local function pickStage()
	local all = stages:GetChildren()
	return all[math.random(1, #all)]
end

-- 모델의 복사본을 타워 꼭대기에 놓고, 복사본과 새로운 꼭대기 높이를 반환합니다
local function stack(template, bottom)
	local copy = template:Clone()
	local box, size = copy:GetBoundingBox()
	local lift = bottom - (box.Position.Y - size.Y / 2)
	copy:PivotTo(copy:GetPivot() + Vector3.new(0, lift, 0))
	copy.Parent = tower
	return copy, bottom + size.Y
end

-- 레슨 14: Reach the Top 코드를 여기에 작성합니다

-- 새로운 무작위 타워를 아래에서부터 쌓아 올립니다
local function buildTower()
	tower = Instance.new("Model")
	tower.Name = "Tower"
	tower.Parent = workspace
	towerStages = {}
	local top = 0
	for i = 1, Settings.StageCount do
		local stage, newTop = stack(pickStage(), top)
		top = newTop
		setupStage(stage)
		towerStages[i] = stage
	end
	stack(ServerStorage.Finish, top)
	return top
end

-- 용암이 지면에서 탑 꼭대기 바로 아래까지 차오릅니다
local function startLava(top)
	lava = Instance.new("Part")
	lava.Name = "Lava"
	lava.Anchored = true
	lava.CanCollide = false
	lava.Size = Vector3.new(30, 2, 30)
	lava.Position = Vector3.new(0, -2, 0)
	lava.Color = Color3.fromRGB(255, 90, 20)
	lava.Material = Enum.Material.Neon
	lava.Parent = workspace
	lava.Touched:Connect(killOnTouch)
	local info = TweenInfo.new(top / Settings.LavaSpeed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, Settings.LavaDelay)
	TweenService:Create(lava, info, { Position = Vector3.new(0, top - 2, 0) }):Play()
end

local function startRound()
	local top = buildTower()
	startLava(top)
	for _, player in Players:GetPlayers() do
		if player.Character then
			player.Character:PivotTo(towerStages[1].Start.CFrame + Vector3.new(0, 4, 0))
		end
	end
end

-- 한 라운드
for i = Settings.Intermission, 1, -1 do
	setBoard("Next tower in " .. i)
	task.wait(1)
end
startRound()
for i = Settings.RoundLength, 1, -1 do
	setBoard("Climb! " .. i .. " seconds left")
	task.wait(1)
end

Roblox 게임: 끝없는 타워의 모든 레슨

직접 연습해 보세요: Roblox 플레이그라운드