모든 패드
Coddy의 Roblox 게임: 팩토리 타이쿤 코스 레슨. 22개 중 10번째.
패드가 네 개 더 남아 있으며, 구매 코드를 네 번 복사하면 모든 버그를 네 번씩 수정해야 합니다. 하나의 함수가 모든 패드를 처리합니다. 각 패드의 Item 속성은 무엇을 구매하는지 나타내며, items:FindFirstChild(name)은 해당 아이템을 찾습니다.
local function buy(pad, player)
-- 이전과 마찬가지로 검사와 가격 처리
build(items:FindFirstChild(pad:GetAttribute("Item")))
endbuild(item)은 아이템을 공장에 배치하고, 그 아이템이 드롭퍼인 경우(Dropper 태그가 있는 경우) 작동을 시작합니다. 벽, 조각상, 업그레이더도 같은 방식으로 배치하며, 드롭퍼만 작동을 시작합니다.
챌린지
중급하나의 함수를 통해 모든 패드가 작동하도록 만드세요.
build(item)을 작성하세요. 아이템을tycoon.Built로 옮기고,item:HasTag("Dropper")이면 시작하세요.buy(pad, player)를 작성하세요. 이전과 같이 확인하고 가격을 처리한 다음, 패드를 ServerStorage로 옮기고Item속성에 지정된 아이템을 빌드하세요.- Dropper2Pad 코드를 사용하는 대신,
tycoon.Buttons에 있는 모든 패드의 Touched를buy에 연결하세요.
‘플레이’를 누르세요. 구매할 수 있는 각 패드가 해당 아이템을 빌드합니다. 그런 다음 ‘확인’을 누르세요.
직접 해보기
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: 드로퍼 아래로 떨어지는, 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
local function startDropper(dropper)
task.spawn(function()
while dropper:IsDescendantOf(workspace) do
dropOre(dropper)
task.wait(Settings.DropInterval)
end
end)
end
-- 컨베이어는 그 위에 놓인 모든 것을 운반합니다
tycoon.Conveyor.AssemblyLinearVelocity = Vector3.new(Settings.BeltSpeed, 0, 0)
-- 수집기는 광석을 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)
-- 두 번째 드로퍼를 구매하는 패드
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
-- 레슨 10: 모든 Pad는 여기에 들어갑니다
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)
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.
Roblox 게임: 팩토리 타이쿤의 모든 레슨
직접 연습해 보세요: Roblox 플레이그라운드