The Conveyor
Lesson 3 of 18 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:
conveyor.AssemblyLinearVelocity = Vector3.new(8, 0, 0)The vector says which way and how fast: 8 studs a second along X. The speed lives in Settings.BeltSpeed.
Challenge
EasySet tycoon.Conveyor.AssemblyLinearVelocity to Settings.BeltSpeed studs a second along X.
Press Play and watch the ore ride (and hop on the belt yourself). 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)
This lesson includes a short quiz. Start the lesson to answer it and track your progress.