구매 패드 하나
Coddy의 Roblox 게임: 공장 타이쿤 코스 레슨. 18개 중 7번째.
현금은 쓰라고 있는 겁니다. 벨트 앞에 있는 파란색 패드마다 구매할 수 있는 항목이 하나씩 있습니다. 첫 번째 패드는 두 번째 드로퍼를 구매합니다. 패드는 월드를 만들 때 설정한 Price 속성에서 가격을 가져옵니다.
구매할 항목은 이미 알맞은 위치인 ServerStorage.TycoonItems에 보관되어 있습니다. 구매하면 해당 항목을 공장의 Built 폴더로 옮겨 월드에 나타나게 하고, 패드는 ServerStorage로 옮겨 아무도 밟을 수 없게 합니다. 삭제하는 것이 아니라 옮기는 것입니다. 이후 강의에서 패드를 다시 가져옵니다.
if cash.Value >= price then
cash.Value -= price
pad.Parent = ServerStorage
items.Dropper2.Parent = tycoon.Built
end패드에 닿는 모든 팔다리마다 Touched 이벤트가 발생하며, 같은 순간에 몇 번씩 발생하기도 합니다. 첫 번째 접촉으로 구매가 이루어지고 나면 패드는 더 이상 tycoon.Buttons에 없으므로, 이를 먼저 확인하면 중복 구매를 막을 수 있습니다.
챌린지
중급첫 번째 패드를 작동시키세요:
ServerStorage를 가져오고,local items = ServerStorage.TycoonItems를 위쪽에 둡니다.- 플레이어가
tycoon.Buttons.Dropper2Pad에 닿았을 때: 해당 플레이어가 소유자가 아니거나 패드가 여전히tycoon.Buttons안에 있지 않으면 아무것도 하지 않습니다. 플레이어의 Cash가 패드의Price속성 값 이상이면 가격을 차감하고, 패드를 ServerStorage로 옮기고,items.Dropper2를tycoon.Built로 옮긴 다음 작동을 시작합니다.
플레이를 눌러 Cash 30을 벌고 구매한 다음, 확인을 누르세요.
직접 해보기
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local Debris = game:GetService("Debris")
local Settings = require(game.ReplicatedStorage.Settings)
local tycoon = workspace.Tycoon
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)
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)
-- 수집기는 광석을 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 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)
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.