Menu
CoddyTech

모든 패드

Coddy의 Roblox 게임: 공장 타이쿤 코스 레슨. 18개 중 9번째.

패드가 네 개 더 남아 있으며, 구매 코드를 네 번 복사하면 모든 버그를 네 번씩 수정해야 합니다. 하나의 함수가 모든 패드를 처리합니다. 각 패드의 Item 속성은 무엇을 구매하는지 나타내며, items:FindFirstChild(name)은 해당 아이템을 찾습니다.

local function buy(pad, player)
	-- 이전과 마찬가지로 검사와 가격 처리
	build(items:FindFirstChild(pad:GetAttribute("Item")))
end
build(item)은 아이템을 공장에 배치하고, 그 아이템이 드롭퍼인 경우(Dropper 태그가 있는 경우) 작동을 시작합니다. 벽, 조각상, 업그레이더도 같은 방식으로 배치하며, 드롭퍼만 작동을 시작합니다.

challenge icon

챌린지

중급

단일 패드의 코드를 교체하세요:

  1. build(item)을 작성하세요. 아이템을 tycoon.Built로 옮기고, Dropper 태그가 있으면 시작하세요.
  2. buy(pad, player)를 작성하세요. 이전과 동일한 확인 및 가격을 적용한 다음, 패드를 ServerStorage로 옮기고 해당 아이템의 Item 속성이 지정하는 아이템을 빌드하세요.
  3. tycoon.Buttons의 모든 패드에 Touched 이벤트를 연결해, 패드를 터치한 플레이어에 대해 buy를 호출하세요.

Play를 눌러 줄을 따라 아이템을 구매한 다음, Check를 누르세요.

직접 해보기

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

local tycoon = workspace.Tycoon
local items = ServerStorage.TycoonItems
local owner = nil

print("Ore is worth " .. Settings.OreValue .. " Cash")

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

	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Parent = leaderstats
end)

-- 공장 위에 있는 간판
local gui = Instance.new("SurfaceGui")
gui.Parent = tycoon.Sign

local signLabel = Instance.new("TextLabel")
signLabel.Name = "Status"
signLabel.Size = UDim2.fromScale(1, 1)
signLabel.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
signLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
signLabel.TextScaled = true
signLabel.Text = "Step on the green pad to claim this factory"
signLabel.Parent = gui

local function setSign(text)
	signLabel.Text = text
end

-- Ore: dropper 아래로 떨어지는, Cash 가치가 있는 작은 부품
local function dropOre(dropper)
	local ore = Instance.new("Part")
	ore.Name = "Ore"
	ore.Size = Vector3.new(1, 1, 1)
	ore.Color = Color3.fromRGB(150, 150, 160)
	ore.Position = dropper.Position - Vector3.new(0, 2.5, 0)
	ore:SetAttribute("Value", Settings.OreValue)
	if math.random() < Settings.GoldChance then
		ore.Color = Color3.fromRGB(255, 200, 40)
		ore.Material = Enum.Material.Neon
		ore:SetAttribute("Value", Settings.OreValue * 5)
	end
	ore.Parent = workspace
	Debris:AddItem(ore, 20)
end

-- dropper는 몇 번 시작되든 하나의 루프만 실행합니다
local function startDropper(dropper)
	if dropper:GetAttribute("Running") then
		return
	end
	dropper:SetAttribute("Running", true)
	task.spawn(function()
		while dropper:IsDescendantOf(workspace) do
			dropOre(dropper)
			task.wait(Settings.DropInterval)
		end
		dropper:SetAttribute("Running", nil)
	end)
end

-- 컨베이어는 그 위에 놓인 모든 것을 운반합니다
tycoon.Conveyor.AssemblyLinearVelocity = Vector3.new(Settings.BeltSpeed, 0, 0)

-- 수집기는 ore를 Cash로 바꿉니다
tycoon.Collector.Touched:Connect(function(hit)
	if hit.Name == "Ore" then
		local value = hit:GetAttribute("Value")
		hit:Destroy()
		if owner then
			owner.leaderstats.Cash.Value += value
		end
	end
end)

-- 두 번째 dropper를 구매하는 패드
local pad = tycoon.Buttons.Dropper2Pad
pad.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if not player or player ~= owner or pad.Parent ~= tycoon.Buttons then
		return
	end
	local cash = player.leaderstats.Cash
	local price = pad:GetAttribute("Price")
	if cash.Value >= price then
		cash.Value -= price
		pad.Parent = ServerStorage
		local dropper = items.Dropper2
		dropper.Parent = tycoon.Built
		startDropper(dropper)
	end
end)

-- 각 패드 위에 가격표가 떠 있습니다
for _, pad in tycoon.Buttons:GetChildren() do
	local tag = Instance.new("BillboardGui")
	tag.Name = "PriceTag"
	tag.Size = UDim2.fromOffset(160, 40)
	tag.StudsOffset = Vector3.new(0, 3, 0)
	tag.Parent = pad

	local label = Instance.new("TextLabel")
	label.Size = UDim2.fromScale(1, 1)
	label.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
	label.BackgroundTransparency = 0.2
	label.TextColor3 = Color3.fromRGB(255, 255, 255)
	label.TextScaled = true
	label.Text = pad:GetAttribute("Label") .. ": $" .. pad:GetAttribute("Price")
	label.Parent = tag
end

-- 소유권 획득: 패드를 처음 밟은 플레이어가 공장의 주인이 됩니다
local claimPad = tycoon.ClaimPad
claimPad.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if player and not owner then
		owner = player
		claimPad.Color = Color3.fromRGB(120, 120, 120)
		claimPad.Material = Enum.Material.SmoothPlastic
		setSign(player.Name .. "'s Factory")
		for _, dropper in CollectionService:GetTagged("Dropper") do
			if dropper:IsDescendantOf(workspace) then
				startDropper(dropper)
			end
		end
	end
end)
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

Roblox 게임: 공장 타이쿤의 모든 레슨