Lesson 01 of 02
Upgrade Data Model
Define your upgrades as data. Never hardcode upgrade logic in your UI.
Separating upgrade data from UI logic is the key to a maintainable shop. Define each upgrade as a table with id, name, description, base price, price scaling, and effect.
luau
1-- ReplicatedStorage/Modules/Upgrades
2local Upgrades = {
3 {
4 id = 'clickPower',
5 name = '⚡ Power Click',
6 description = 'Doubles your click value!',
7 basePrice = 10,
8 priceMultiplier = 2.5, -- each level costs 2.5x more
9 maxLevel = 10,
10 },
11 {
12 id = 'autoClick',
13 name = '🤖 Auto Clicker',
14 description = '+1 coin/second automatically',
15 basePrice = 25,
16 priceMultiplier = 3,
17 maxLevel = 20,
18 },
19 {
20 id = 'critChance',
21 name = '💥 Crit Chance',
22 description = '10% chance of 10x click value',
23 basePrice = 100,
24 priceMultiplier = 2,
25 maxLevel = 5,
26 },
27}
28
29function Upgrades.getPrice(upgrade, currentLevel: number): number
30 return math.floor(upgrade.basePrice * (upgrade.priceMultiplier ^ currentLevel))
31end
32
33return Upgrades
READY · 33 lines
