구매 패드
Coddy의 Roblox 게임: 팩토리 타이쿤 코스 레슨. 22개 중 8번째.
현금은 쓰라고 있는 겁니다. 벨트 앞에 있는 파란색 패드마다 구매할 수 있는 항목이 하나씩 있습니다. 첫 번째 패드는 두 번째 드로퍼를 구매합니다. 패드는 월드를 만들 때 설정한 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에 없으므로, 이를 먼저 확인하면 중복 구매를 막을 수 있습니다.
챌린지
중급첫 번째 파란색 패드에서 두 번째 드로퍼를 구매하도록 만드세요.
- 위쪽 근처에 다음을 추가하세요:
local items = ServerStorage.TycoonItems. tycoon.Buttons.Dropper2Pad의 Touched 이벤트에서 플레이어가owner가 아니거나 패드가tycoon.Buttons안에 있지 않으면 반환하세요.- 플레이어의 Cash가
Price속성값 이상이면 Cash를 차감하고, 패드를 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)
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)
-- 레슨 8: 여기에 구매 패드를 설치합니다
-- 소유권 획득: 패드를 처음 밟은 플레이어가 공장의 주인이 됩니다
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 플레이그라운드