Menu
CoddyTech

업그레이더

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

벨트 위의 보라색 문은 업그레이더입니다. 광석을 막지는 않지만(CanCollide가 아니므로), 이 문을 통과하는 모든 광석의 가치는 두 배가 됩니다.

같은 광석에 대해 Touched가 두 번 이상 실행될 수 있습니다. 예를 들어 광석이 멈췄다가 다시 움직이는 경우가 그렇습니다. 두 배로 만드는 작업이 두 번 이루어지면 플레이어는 좋아하고 소유자는 싫어하는 버그가 발생합니다. 따라서 업그레이더는 두 배로 만든 각 광석에 속성을 표시하고, 표시된 광석은 건너뜁니다.

if hit.Name == "Ore" and not hit:GetAttribute("Upgraded") then
	hit:SetAttribute("Upgraded", true)
	hit:SetAttribute("Value", hit:GetAttribute("Value") * 2)
end

업그레이더는 구매될 때까지 ServerStorage에서 대기하지만, Touched는 시작할 때 연결할 수 있습니다. 연결은 파트가 어디에 있든 파트에 유지되며, Touched는 파트가 월드에 들어온 뒤에만 실행됩니다.

challenge icon

챌린지

중급

items.Upgrader.Touched를 연결합니다. 파트 이름이 Ore이고 Upgraded 속성이 없으면 Upgraded를 true로 설정하고, Value를 두 배로 만든 다음 보라색으로 색칠합니다(Color3.fromRGB(155, 89, 182)).

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: 드로퍼 아래로 떨어지는 작은 부품으로, 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 function build(item)
	item.Parent = tycoon.Built
	if item:HasTag("Dropper") then
		startDropper(item)
	end
end

-- 구매: 패드가 사라지고 해당 아이템이 설치된다
local function buy(pad, player)
	if 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
		return
	end
	cash.Value -= price
	pad.Parent = ServerStorage
	build(items:FindFirstChild(pad:GetAttribute("Item")))
end

for _, pad in tycoon.Buttons:GetChildren() do
	pad.Touched:Connect(function(hit)
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			buy(pad, player)
		end
	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 게임: 공장 타이쿤의 모든 레슨