Налаштування таблиці лідерів
У провіднику в розділі ServerScriptService створіть новий сценарій:
local Players = game:GetService("Players")
-- Creates a leaderboard that shows player variables
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local items = Instance.new("IntValue")
items.Name = "Items"
items.Value = 0
items.Parent = leaderstats
local spaces = Instance.new("IntValue")
spaces.Name = "Spaces"
spaces.Value = 2
spaces.Parent = leaderstats
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 0
gold.Parent = leaderstats
end
-- Run onPlayerJoin when the PlayerAdded event fires
Players.PlayerAdded:Connect(onPlayerJoin)
створіть BoolValue під назвою CanHarvest, щоб відстежувати його статус.

У властивостях BoolValue поставте прапорець у полі «Value».
Додавання інструменту
Щоб гравці могли використовувати початковий інструмент, завантажте та помістіть його в StarterPack.
У StarterPack у розділі StarterTool додайте новий сценарій:
local tool = script.Parent
local toolPart = tool.Handle
local backpack = tool.Parent
local player = backpack.Parent
local playerStats = player:FindFirstChild("leaderstats")
local playerItems = playerStats:FindFirstChild("Items")
local playerSpaces = playerStats:FindFirstChild("Spaces")
local function onTouch(partTouched)
local canHarvest = partTouched:FindFirstChild("CanHarvest")
if canHarvest then
print("Found an item")
if canHarvest.Value == true and playerItems.Value < playerSpaces.Value then
playerItems.Value += 1
canHarvest.Value = false
-- Reset partTouched, the harvested item
partTouched.Transparency = 1
partTouched.CanCollide = false
task.wait(10)
-- Make the harvested item reappear and usable again
canHarvest.Value = true
partTouched.Transparency = 0
partTouched.CanCollide = true
end
end
end
toolPart.Touched:Connect(onTouch)
Створіть новий Part під назвою SellPlatform. Налаштуйте його відповідно до теми вашого досвіду.

У SellPlatform створіть новий сценарій:
-- Sells all a player's items and gives them gold
local sellPart = script.Parent
local Players = game:GetService("Players")
local function sellItems(playerItems, playerGold)
local totalSell = playerItems.Value * 100
playerGold.Value += totalSell
playerItems.Value = 0
end
local function onTouch (partTouched)
local character = partTouched.Parent
local player = Players:GetPlayerFromCharacter(character)
if player then
-- Gets the player's leaderboard. Needed to get items and money
local playerStats = player:FindFirstChild("leaderstats")
if playerStats then
-- Gets the player's items and money
local playerItems = playerStats:FindFirstChild("Items")
local playerGold = playerStats:FindFirstChild("Gold")
print("A player touched sellPart")
if playerItems and playerGold then
sellItems(playerItems, playerGold)
end
end
end
end
sellPart.Touched:Connect(onTouch)
Створення магазину
У робочій області створіть нову модель під назвою «Магазин» та додайте ClickDetector
Додайте скрипт у цю модель:
-- Lets players click a button to buy an upgrade that increases Spaces
local buyButton = script.Parent
local clickDetector = buyButton.ClickDetector
-- Variables for the upgrade
local newSpaces = 5
local upgradeCost = 100
local function giveUpgrade(player)
print("Someone clicked the button")
-- Get's the player's leaderboard to get other IntValues
local playerStats = player:FindFirstChild("leaderstats")
if playerStats then
-- Gets the player's money and spaces to make changes
local playerGold = playerStats:FindFirstChild("Gold")
local playerSpaces = playerStats:FindFirstChild("Spaces")
-- Checks if player has enough money to afford the upgrade
if playerGold and playerSpaces and playerGold.Value >= upgradeCost then
-- Subtract the item's cost from the player's money
playerGold.Value -= upgradeCost
playerSpaces.Value += newSpaces
end
end
end
clickDetector.MouseClick:Connect(giveUpgrade)