Hover over ServerScriptService, click + and add a Script. Name it Stats.
Delete the line that is already there and paste this code.
Press Play. The player list shows Power 0 and Coins 0.
ServerScriptService > Stats
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = player
for _, name in ipairs({"Power", "Coins"}) do
local value = Instance.new("IntValue")
value.Name = name
value.Parent = stats
end
local multiplier = Instance.new("IntValue")
multiplier.Name = "Multiplier"
multiplier.Value = 1
multiplier.Parent = player
end)
What each part does
The loop creates two values with one piece of code: Power and Coins.
Multiplier is how much power one click gives. It starts at 1.
Multiplier sits on the player and not in leaderstats, so it stays hidden from the player list.
More detail
When you click +, type the word Script to find it quickly.
The script opens in a new tab. Click inside the code, press Ctrl+A and then Ctrl+V to replace everything.
Rename the script in Explorer with F2. The name is only for you. It helps you find the script later.
The player list is in the top right corner of the game.
This step does not work for me
Check these three things first
The name of every part and script is exactly as in the guide, with the same capital letters.
The script sits inside the right object. Look at the label above the code box.
Open the Output window from the Window menu. Red text shows the script and the line with the problem.
Add a Part. Set Size to 6, 8, 6, turn on Anchored and name it Crystal. Pick a bright color and set Material to Neon.
Hover over Crystal, click + and add a ClickDetector.
Add a Script to Crystal and paste this code.
Press Play and click the crystal. Power goes up by 1 on every click.
Crystal > Script
local crystal = script.Parent
local clickDetector = crystal.ClickDetector
clickDetector.MouseClick:Connect(function(player)
local power = player.leaderstats.Power
power.Value += player.Multiplier.Value
end)
What each part does
A ClickDetector makes a part clickable. It also works with taps on phones.
MouseClick tells the script which player clicked.
The script adds the player's Multiplier to Power, so upgrades make every click stronger.
More detail
Type the size into the Size field in Properties and press Enter. Then lift the crystal with the Move tool until it stands on the floor.
When you click +, type ClickDetector to find it. In Explorer it must sit one step to the right, under Crystal.
In the game, the mouse pointer changes to a hand when it is over the crystal.
You must stand close enough. A ClickDetector works from 32 studs away or less.
Common mistake. Nothing happens on click: the ClickDetector must sit directly inside Crystal, next to the script.
This step does not work for me
Check these three things first
The name of every part and script is exactly as in the guide, with the same capital letters.
The script sits inside the right object. Look at the label above the code box.
Open the Output window from the Window menu. Red text shows the script and the line with the problem.
Add a Part on the floor. Set Size to 8, 1, 8, turn on Anchored, make it yellow and name it Sell.
Add a Script to Sell and paste this code.
Press Play, click the crystal a few times and walk onto the pad. Power turns into Coins.
Sell > Script
local Players = game:GetService("Players")
local pad = script.Parent
pad.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
local stats = player.leaderstats
if stats.Power.Value > 0 then
stats.Coins.Value += stats.Power.Value
stats.Power.Value = 0
end
end)
What each part does
GetPlayerFromCharacter finds the player who stepped on the pad.
The pad adds all of the player's Power to Coins and then sets Power back to 0.
More detail
A pad is a flat part that players walk onto.
Put the pad flat on the floor. If it is too high, players cannot step onto it.
Walking onto the pad with 0 power does nothing. That is correct.
To test: click the crystal 10 times, walk onto the pad, and the player list shows Power 0 and Coins 10.
This step does not work for me
Check these three things first
The name of every part and script is exactly as in the guide, with the same capital letters.
The script sits inside the right object. Look at the label above the code box.
Open the Output window from the Window menu. Red text shows the script and the line with the problem.
Add another Part on the floor. Set Size to 8, 1, 8, turn on Anchored, make it blue and name it Upgrade.
Add a Script to Upgrade and paste this code.
Press Play, earn 25 coins and step on the pad. Every click now gives 2 power.
Upgrade > Script
local Players = game:GetService("Players")
local pad = script.Parent
local waiting = {}
pad.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not player or waiting[player] then return end
local price = player.Multiplier.Value * 25
local coins = player.leaderstats.Coins
if coins.Value < price then return end
waiting[player] = true
coins.Value -= price
player.Multiplier.Value += 1
task.wait(1)
waiting[player] = nil
end)
What each part does
The price is the player's Multiplier times 25, so each upgrade costs more than the one before.
The waiting table stops one long step on the pad from buying many upgrades at once.
After the purchase the Multiplier goes up by 1.
More detail
Put the pad a few steps away from the sell pad, so players do not buy by accident.
The first upgrade costs 25 coins. After it, Coins drops by 25 and one click gives 2 power.
With fewer coins than the price, the pad does nothing. Step off, earn more and come back.
The 1 second pause is why holding still on the pad buys only one upgrade at a time.
This step does not work for me
Check these three things first
The name of every part and script is exactly as in the guide, with the same capital letters.
The script sits inside the right object. Look at the label above the code box.
Open the Output window from the Window menu. Red text shows the script and the line with the problem.