A placa
Lição 7 de 22 do curso Jogo no Roblox: Magnata da Fábrica da Coddy.
Uma placa acima da fábrica informa de quem ela é. O texto na face de uma peça é um SurfaceGui na peça, que contém um TextLabel. É fácil encontrar os rótulos nomeados novamente, e uma função pequena mantém todas as alterações na placa em um só lugar:
local gui = Instance.new("SurfaceGui")
gui.Parent = tycoon.Sign
local signLabel = Instance.new("TextLabel")
signLabel.Name = "Status"
signLabel.Size = UDim2.fromScale(1, 1)
signLabel.TextScaled = true
signLabel.Text = "Opening soon"
signLabel.Parent = guiUDim2.fromScale(1, 1) faz o rótulo preencher toda a face, e TextScaled ajusta as palavras a ela.
Desafio
MédioColoque uma placa acima da fábrica indicando de quem ela é.
- Em
tycoon.Sign, adicione um SurfaceGui contendo um TextLabel chamadoStatusque preencha toda a superfície, com texto dimensionado que exibaStep on the green pad to claim this factory. - Escreva
setSign(text), que define o Text dessa etiqueta. - Quando a fábrica for reivindicada, chame
setSign(player.Name .. "'s Factory").
Pressione “Jogar” e pise no bloco verde: a placa exibirá seu nome. Depois, pressione “Verificar”.
Experimente você mesmo
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")
-- Todo jogador recebe Cash no placar
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)
-- Lição 7: a placa Sign vai aqui
-- Ore: uma pequena peça que vale Cash, solta embaixo de um dropper
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
-- A esteira transporta tudo o que estiver sobre ela
tycoon.Conveyor.AssemblyLinearVelocity = Vector3.new(Settings.BeltSpeed, 0, 0)
-- O coletor transforma Ore em 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)
-- Reivindicação: o primeiro jogador a pisar na plataforma se torna dono da fábrica
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
for _, dropper in CollectionService:GetTagged("Dropper") do
if dropper:IsDescendantOf(workspace) then
startDropper(dropper)
end
end
end
end)
Todas as lições de Jogo no Roblox: Magnata da Fábrica
Pratique por conta própria: Playground de Roblox