Menu
CoddyTech

The Dropper

Lesson 2 of 22 in Coddy's Roblox Game: Factory Tycoon course.

Money starts with ore. The grey box over the conveyor, workspace.Tycoon.Dropper, drops a small part every second. Each ore carries what it is worth as an attribute, a named value you can store on any instance:

ore:SetAttribute("Value", 25)
print(ore:GetAttribute("Value")) --> 25

The drop happens forever, so it is a loop. A loop that waits would hold up the rest of the script, so the dropper's loop runs alongside it, in task.spawn, and stops if the dropper ever leaves the world:

task.spawn(function()
	while dropper:IsDescendantOf(workspace) do
		dropOre(dropper)
		task.wait(Settings.DropInterval)
	end
end)

A new Part is unanchored unless you anchor it, so the ore falls out of the dropper by itself.

challenge icon

Challenge

Easy

Make the dropper drop ore.

  1. Near the top: local tycoon = workspace.Tycoon.
  2. Write dropOre(dropper): a 1, 1, 1 Part named Ore, 2.5 studs below the dropper, with a Value attribute of Settings.OreValue, in the workspace.
  3. Write startDropper(dropper): in task.spawn, while the dropper is in the workspace, drop ore every Settings.DropInterval. Call it for tycoon.Dropper.

Press Play: grey ore piles up under the dropper. Then Check.

Try it yourself

local Players = game:GetService("Players")
local Settings = require(game.ReplicatedStorage.Settings)

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)

-- Lesson 2: The Dropper goes here

All lessons in Roblox Game: Factory Tycoon

Practice on your own: Roblox playground