The Conveyor
Lesson 3 of 22 in Coddy's Roblox Game: Factory Tycoon course.
Ore piling up under the dropper earns nothing. It has to travel to the collector, and a conveyor takes it there.
In Roblox a conveyor is an anchored part with a velocity. Setting AssemblyLinearVelocity on an anchored part moves nothing by itself, but whatever rests on it is carried along at that speed, players included:
tycoon.Conveyor.AssemblyLinearVelocity = Vector3.new(12, 0, 0)The vector says which way and how fast: 12 studs a second along X. Your game's speed lives in Settings.BeltSpeed.
Challenge
EasyRun the conveyor so it carries the ore to the collector.
- Under the dropper code, set
tycoon.Conveyor.AssemblyLinearVelocity. - Make it
Vector3.new(Settings.BeltSpeed, 0, 0): BeltSpeed studs a second along X.
Press Play: the ore rides the belt to the green block, and so do you if you hop on. Then Check.
Try it yourself
local Players = game:GetService("Players")
local Settings = require(game.ReplicatedStorage.Settings)
local tycoon = workspace.Tycoon
print("Ore is worth " .. Settings.OreValue .. " Cash")
-- Every player gets Cash on the leaderboard
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)
-- Ore: a small part worth Cash, dropped under a 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)
ore.Parent = workspace
end
local function startDropper(dropper)
task.spawn(function()
while dropper:IsDescendantOf(workspace) do
dropOre(dropper)
task.wait(Settings.DropInterval)
end
end)
end
startDropper(tycoon.Dropper)
-- Lesson 3: The Conveyor goes here
All lessons in Roblox Game: Factory Tycoon
Practice on your own: Roblox playground