重點摘要
Roblox 的模擬器就是一個循環:點擊賺金幣,花金幣買讓你賺更多的升級,然後重生換取永久倍率。價格放在 ReplicatedStorage 的 ModuleScript 中。ServerScriptService 中的一個 Script 保存每位玩家的 Coins、Click Power 與 Rebirths,從 Click RemoteEvent 每秒最多採計 15 次點擊,並在檢查價格後透過 RemoteFunction 販售升級與重生。LocalScript 顯示 Click、Upgrade 與 Rebirth 按鈕。以本教學的數值,每秒點 5 下的玩家大約 1.2 分鐘就能第一次重生,節奏表說明要改什麼才能讓爬升更久。
本頁內容
模擬器的核心循環是怎麼組成的
模擬器是由三個動作組成的循環。玩家一再做一件簡單的事來賺取貨幣,把它花在讓他賺得更快的升級上,當升級變貴時就重生:交出金幣與升級,換取永久保留的加成,然後再次爬升,而且更快。其他模擬器把點擊換成舉啞鈴、挖礦或收集物品,但底下的循環是一樣的。
| 動作 | 花費 | 得到 | 由誰決定 |
|---|---|---|---|
| 點擊 | 免費 | 金幣,等於 Click Power × (Rebirths + 1) | 伺服器,在每個一秒長的時間窗內最多採計 15 次點擊 |
| 升級 | 10 金幣,之後每升一級都是前一個價格的 1.5 倍 | Click Power 再升一級,最高到 50 級 | 伺服器,依照它自己那份價格 |
| 重生 | 1,000 金幣,之後每次重生都是前一個價格的 3 倍 | 金幣歸 0,Click Power 回到等級 1,加上永久 +1 倍率 | 伺服器 |
每個數值都在伺服器上。玩家的裝置畫出按鈕並提出請求(「我點了」、「我想升級」),由伺服器決定它值多少以及能不能做。被破解的點擊遊戲 Script,往往是在 LocalScript 中加金幣,或讓用戶端傳送要加多少金幣。
| 部分 | 位置 | 作用 |
|---|---|---|
ModuleScript SimulatorConfig | ReplicatedStorage | 點擊價值、升級價格與重生價格的價格、限制與公式。兩邊都會讀取它。 |
Script SimulatorService | ServerScriptService | 保存每位玩家的數值,處理點擊、升級與重生,並填入 leaderstats。 |
Folder SimulatorRemotes | ReplicatedStorage(由 SimulatorService 建立) | RemoteEvent Click,以及 RemoteFunction BuyUpgrade 與 Rebirth。 |
LocalScript SimulatorClient | StarterPlayerScripts | 組出按鈕,傳送點擊與請求,並顯示伺服器的數值。 |
ModuleScript PlayerData(選用) | ServerScriptService | 在不同次進入遊戲之間保存進度。它來自DataStore 教學,只有步驟 4 需要。 |
ReplicatedStorage
SimulatorConfig ModuleScript new
SimulatorRemotes Folder new
Click RemoteEvent new
BuyUpgrade RemoteFunction new
Rebirth RemoteFunction new
ServerScriptService
SimulatorService Script new
PlayerData ModuleScript
StarterPlayer
StarterPlayerScripts
SimulatorClient LocalScript new
步驟 1:把價格與公式放進模組
每個你可能想調整的數值都放進一個 ModuleScript:點擊值多少、每次升級和重生要多少,以及點擊次數上限。伺服器依它做決定,LocalScript 從它取得按鈕上的價格,所以任何修改都只要在一個地方改一次。
- 在 Explorer 中把游標移到 ReplicatedStorage 上,按 + 按鈕,插入一個 ModuleScript。
- 把它改名為
SimulatorConfig(名稱有分大小寫),並把內容換成下面的程式碼。
-- 核心循環的所有數值,以及兩邊共用的公式。用戶端只用它們
-- 顯示價格;伺服器依照自己的那一份做決定。
local SimulatorConfig = {}
SimulatorConfig.UPGRADE_BASE_COST = 10 -- Click Power 等級 2 的價格
SimulatorConfig.UPGRADE_COST_GROWTH = 1.5 -- 每一級的價格是前一級的 1.5 倍
SimulatorConfig.MAX_POWER_LEVEL = 50
SimulatorConfig.REBIRTH_BASE_COST = 1000 -- 第一次重生需要的金幣
SimulatorConfig.REBIRTH_COST_GROWTH = 3 -- 每次重生的價格是前一次的 3 倍
SimulatorConfig.MAX_CLICKS_PER_SECOND = 15 -- 一秒內超過這個數量的點擊會被忽略
-- 每次點擊的金幣:Click Power 等級乘以 1 + 重生次數
function SimulatorConfig.clickValue(powerLevel: number, rebirths: number): number
return powerLevel * (rebirths + 1)
end
-- 下一個 Click Power 等級的價格
function SimulatorConfig.upgradeCost(powerLevel: number): number
return math.floor(SimulatorConfig.UPGRADE_BASE_COST * SimulatorConfig.UPGRADE_COST_GROWTH ^ (powerLevel - 1))
end
-- 下一次重生需要的金幣
function SimulatorConfig.rebirthCost(rebirths: number): number
return SimulatorConfig.REBIRTH_BASE_COST * SimulatorConfig.REBIRTH_COST_GROWTH ^ rebirths
end
return SimulatorConfig
玩家可以讀取 ReplicatedStorage 中的 ModuleScript,所以這些價格是公開的。這沒關係:它們本來就寫在按鈕上。用戶端和伺服器各自執行自己那份模組,所以在自己裝置上改數值的玩家,不會改變伺服器上的任何東西。
| Click Power 等級 | 下一級價格 | 每次點擊金幣(無重生) | 每次點擊金幣(1 次重生) |
|---|---|---|---|
| 1 | 10 | 1 | 2 |
| 2 | 15 | 2 | 4 |
| 3 | 22 | 3 | 6 |
| 4 | 33 | 4 | 8 |
| 5 | 50 | 5 | 10 |
重生需要 1,000 金幣,接著是 3,000,再來是 9,000,因為 rebirthCost 每次都把價格乘以 3。重生一次後,每次點擊的價值變成兩倍,重生兩次後變成三倍,依此類推。
以這些數值,一次重生要多久
公式決定循環要花多久,所以最好在玩家之前先把數字算出來。這張表假設玩家一付得起就重生,其餘時間則在付得起、而且價格低於重生時購買下一個 Click Power 等級。時間從全新開始計算,所以最後一欄是到第 3 次重生的總時間。
REBIRTH_BASE_COST | 第 1 次重生 | 第 2 次重生 | 第 3 次重生 |
|---|---|---|---|
| 1,000(本教學) | 1.2 | 2.7 | 4.8 |
| 5 000 | 4.3 | 10.1 | 18.3 |
| 10 000 | 8.2 | 16.9 | 33.2 |
| 25 000 | 16.7 | 40.1 | 74.5 |
| 50 000 | 32.8 | 68.8 | 137.8 |
沒有重生時,Click Power 等級 5 在 34 次點擊後達到,等級 10 在 122 次後,等級 13 在 285 次後。以預設數值,玩家在這之後就不再升級,因為等級 14 要 1,297 金幣,比 1,000 金幣的重生還貴,第一次重生總共在 362 次點擊後到來。以伺服器每秒 15 次點擊的上限,把每個時間除以 3。只要改了 SimulatorConfig 中的任何數值,這些時間就會跟著改變,所以請重新計算。
調整成長幅度
兩個 _GROWTH 數值決定價格成長得多快。在 1.5 時,每次升級都比前一次貴一半,而每一級只讓每次點擊多一枚金幣(在重生倍率之前),所以每個新等級回本的時間越來越長。正是這種減速讓重生變得划算。調高成長幅度可以讓爬升更久,調低則更快,並讓 REBIRTH_BASE_COST 保持夠高,讓玩家在第一次重生前買幾次升級。
想讓第一次重生在幾分鐘後,而不是大約一分鐘後,請把 REBIRTH_BASE_COST 調高到 5,000 或 10,000。
步驟 2:加入伺服器 Script
這個 Script 擁有每一個數值。它建立 remote,給每位玩家一個含有 Coins 與 Rebirths 的 leaderstats 資料夾,並回應三種請求。把游標移到 ServerScriptService 上,插入一個 Script,改名為 SimulatorService,並把內容換成這段程式碼:
-- 擁有每一個數值:點擊在這裡賺金幣,升級與重生在這裡購買,
-- leaderstats 只負責顯示結果。
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
-- false:每次進入時所有人都從零開始。true:透過 PlayerData 模組載入與儲存
-- (來自 DataStore 教學,請先在它的 DEFAULTS 中加入 PowerLevel = 1 與 Rebirths = 0)。
local SAVE_PROGRESS = false
type Config = {
MAX_POWER_LEVEL: number,
MAX_CLICKS_PER_SECOND: number,
clickValue: (powerLevel: number, rebirths: number) -> number,
upgradeCost: (powerLevel: number) -> number,
rebirthCost: (rebirths: number) -> number,
}
local Config = require(ReplicatedStorage:WaitForChild("SimulatorConfig")) :: Config
type Stats = { Coins: number, PowerLevel: number, Rebirths: number }
local remotes = Instance.new("Folder")
remotes.Name = "SimulatorRemotes"
local clickEvent = Instance.new("RemoteEvent")
clickEvent.Name = "Click"
clickEvent.Parent = remotes
local buyUpgrade = Instance.new("RemoteFunction")
buyUpgrade.Name = "BuyUpgrade"
buyUpgrade.Parent = remotes
local rebirthRemote = Instance.new("RemoteFunction")
rebirthRemote.Name = "Rebirth"
rebirthRemote.Parent = remotes
remotes.Parent = ReplicatedStorage
local playerStats: { [Player]: Stats } = {}
local windowStart: { [Player]: number } = {} -- 這位玩家目前一秒時間窗開始的時間
local clickCount: { [Player]: number } = {} -- 這個時間窗內採計的點擊次數
-- 把伺服器的數值複製到玩家看得到的地方:leaderstats 與一個屬性
local function refresh(player: Player)
local data = playerStats[player]
local leaderstats = player:FindFirstChild("leaderstats")
if not (data and leaderstats) then
return
end
local coins = leaderstats:FindFirstChild("Coins")
local rebirths = leaderstats:FindFirstChild("Rebirths")
if coins and coins:IsA("IntValue") then
coins.Value = data.Coins
end
if rebirths and rebirths:IsA("IntValue") then
rebirths.Value = data.Rebirths
end
player:SetAttribute("PowerLevel", data.PowerLevel)
end
-- 用傳入的資料讓玩家開始(新的數值或已儲存的表)
local function setup(player: Player, data: Stats)
playerStats[player] = data
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
for _, name in { "Coins", "Rebirths" } do
local value = Instance.new("IntValue")
value.Name = name
value.Parent = leaderstats
end
leaderstats.Parent = player
refresh(player)
end
-- 點擊不帶任何數值:它值多少由伺服器計算
clickEvent.OnServerEvent:Connect(function(player: Player)
local data = playerStats[player]
if not data then
return
end
local now = os.clock()
local start = windowStart[player]
if not start or now - start >= 1 then
windowStart[player] = now
clickCount[player] = 0
end
local count = clickCount[player] or 0
if count >= Config.MAX_CLICKS_PER_SECOND then
return -- 連點器,或在迴圈中呼叫 remote 的 Script
end
clickCount[player] = count + 1
data.Coins += Config.clickValue(data.PowerLevel, data.Rebirths)
refresh(player)
end)
buyUpgrade.OnServerInvoke = function(player: Player): (boolean, string)
local data = playerStats[player]
if not data then
return false, "Your stats have not loaded yet."
end
if data.PowerLevel >= Config.MAX_POWER_LEVEL then
return false, "Click Power is maxed out."
end
local cost = Config.upgradeCost(data.PowerLevel)
if data.Coins < cost then
return false, `You need {cost - data.Coins} more coins.`
end
data.Coins -= cost
data.PowerLevel += 1
refresh(player)
return true, `Click Power is now level {data.PowerLevel}.`
end
rebirthRemote.OnServerInvoke = function(player: Player): (boolean, string)
local data = playerStats[player]
if not data then
return false, "Your stats have not loaded yet."
end
local cost = Config.rebirthCost(data.Rebirths)
if data.Coins < cost then
return false, `You need {cost - data.Coins} more coins to rebirth.`
end
-- 重生把金幣與升級換成永久倍率
data.Coins = 0
data.PowerLevel = 1
data.Rebirths += 1
refresh(player)
return true, `Rebirth {data.Rebirths}! Every click is now worth x{data.Rebirths + 1}.`
end
-- 起始數值:新的,或由 PlayerData 模組載入並儲存的表
if SAVE_PROGRESS then
type PlayerDataModule = {
Loaded: RBXScriptSignal,
Get: (player: Player) -> any,
}
local PlayerData = require(ServerScriptService:WaitForChild("PlayerData")) :: PlayerDataModule
local function onLoaded(player: Player)
local data = PlayerData.Get(player)
if not data or playerStats[player] then
return
end
if type(data.Coins) ~= "number" or type(data.PowerLevel) ~= "number" or type(data.Rebirths) ~= "number" then
warn("SimulatorService: add PowerLevel = 1 and Rebirths = 0 to DEFAULTS in the PlayerData module")
return
end
setup(player, data) -- PlayerData 儲存的同一張表,所以每個變更都會被儲存
end
PlayerData.Loaded:Connect(onLoaded)
for _, player in Players:GetPlayers() do
onLoaded(player) -- 所有在這個 Script 執行前就已經載入資料的玩家
end
else
local function onPlayerAdded(player: Player)
setup(player, { Coins = 0, PowerLevel = 1, Rebirths = 0 })
end
Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in Players:GetPlayers() do
onPlayerAdded(player)
end
end
Players.PlayerRemoving:Connect(function(player: Player)
playerStats[player] = nil
windowStart[player] = nil
clickCount[player] = nil
end)
Click Power 是以玩家 Player 物件上的 PowerLevel 屬性傳給玩家的,而不是 leaderstats 中的第三個數值,所以玩家清單只顯示 Coins 與 Rebirths。伺服器設定的屬性會複寫到玩家的裝置;玩家在自己裝置上做的變更只會留在那裡。
點擊與頻率限制
Click remote 不傳任何引數。在伺服器上,OnServerEvent 處理函式的第一個參數永遠是呼叫它的玩家,所以伺服器知道是誰點的,取得他的 Click Power 等級與 Rebirths,並把 clickValue 加到他的 Coins。請求中沒有任何作弊者能改的東西。
Roblox 的安全指南說絕對不要只依賴用戶端的頻率限制,而發放貨幣正列在需要限制的動作之中。伺服器以一秒為時間窗計算每位玩家的點擊:第一次點擊開啟時間窗,採計滿 15 次點擊後,其餘的會被忽略,直到時間窗開始後過了一秒。在迴圈中呼叫 remote 的 Script,每個時間窗最多只會被採計 15 次點擊。要允許點得更快或更慢,請修改 SimulatorConfig 中的 MAX_CLICKS_PER_SECOND。
升級與重生
BuyUpgrade 與 Rebirth 是 RemoteFunction,所以按鈕可以等待回覆並顯示出來。每個處理函式都從伺服器那份 SimulatorConfig 取得價格,檢查玩家的 Coins,之後才做任何變更。它回傳 true 或 false 以及一則訊息,例如 "You need 5 more coins.",由 LocalScript 顯示在狀態列中。
在檢查價格與做出變更之間,沒有任何東西會等待或讓出執行(yield),所以同一位玩家的兩個請求,不可能在第一個扣掉金幣之前都通過檢查。重生把 Coins 設為 0、Click Power 設為等級 1,並把 Rebirths 加 1,點擊公式再把它變成 Rebirths + 1 的倍率。
SAVE_PROGRESS 開關
SAVE_PROGRESS = false 時,每位玩家每次進入都從 0 金幣開始,這正是你在製作遊戲期間需要的。步驟 4 會把它打開。到時 Script 會等 PlayerData 模組載入每位玩家,並直接操作這個模組儲存的那張表,所以每一枚金幣和每一次重生都會被儲存,不需要額外的程式碼。
步驟 3:組出按鈕
這個 LocalScript 用程式碼組出整個畫面:上方的金幣計數器、中間的大 Click 按鈕、下方的 Upgrade 與 Rebirth 按鈕,以及顯示伺服器回覆的狀態列。它自己從不改變任何數值。
- 在 Explorer 中展開 StarterPlayer,把游標移到 StarterPlayerScripts 上,插入一個名為
SimulatorClient的 LocalScript。 - 把它的內容換成下面的程式碼,然後按 Play。
-- 組出模擬器的按鈕並顯示伺服器的數值。它自己從不改變它們。
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
type Config = {
MAX_POWER_LEVEL: number,
clickValue: (powerLevel: number, rebirths: number) -> number,
upgradeCost: (powerLevel: number) -> number,
rebirthCost: (rebirths: number) -> number,
}
local Config = require(ReplicatedStorage:WaitForChild("SimulatorConfig")) :: Config
local remotes = ReplicatedStorage:WaitForChild("SimulatorRemotes")
local clickEvent = remotes:WaitForChild("Click") :: RemoteEvent
local buyUpgrade = remotes:WaitForChild("BuyUpgrade") :: RemoteFunction
local rebirthRemote = remotes:WaitForChild("Rebirth") :: RemoteFunction
local player = Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins") :: IntValue
local rebirths = leaderstats:WaitForChild("Rebirths") :: IntValue
local BOLD = Font.fromEnum(Enum.Font.BuilderSansBold)
-- 1234 -> "1.2K", 5600000 -> "5.6M"
local UNITS = {
{ size = 1e12, suffix = "T" },
{ size = 1e9, suffix = "B" },
{ size = 1e6, suffix = "M" },
{ size = 1e3, suffix = "K" },
}
local function short(n: number): string
for _, unit in UNITS do
if n >= unit.size then
return string.format("%.1f%s", math.floor(n / unit.size * 10) / 10, unit.suffix)
end
end
return tostring(n)
end
local function newButton(parent: Instance, text: string, position: UDim2, size: UDim2, color: Color3): TextButton
local button = Instance.new("TextButton")
button.AnchorPoint = Vector2.new(0.5, 0.5)
button.Position = position
button.Size = size
button.BackgroundColor3 = color
button.TextColor3 = Color3.new(1, 1, 1)
button.FontFace = BOLD
button.TextScaled = true
button.Text = text
button.Parent = parent
local corner = Instance.new("UICorner")
corner.CornerRadius = UDim.new(0, 12)
corner.Parent = button
return button
end
local gui = Instance.new("ScreenGui")
gui.Name = "SimulatorGui"
gui.ResetOnSpawn = false
local coinsLabel = Instance.new("TextLabel")
coinsLabel.AnchorPoint = Vector2.new(0.5, 0)
coinsLabel.Position = UDim2.new(0.5, 0, 0, 12)
coinsLabel.Size = UDim2.fromOffset(320, 48)
coinsLabel.BackgroundTransparency = 1
coinsLabel.TextColor3 = Color3.fromRGB(255, 214, 90)
coinsLabel.FontFace = BOLD
coinsLabel.TextScaled = true
coinsLabel.Parent = gui
local clickButton = newButton(gui, "Click!", UDim2.new(0.5, 0, 0.5, -30), UDim2.fromScale(0.38, 0.38), Color3.fromRGB(124, 77, 255))
-- Click 按鈕保持正方形,依螢幕大小縮放,最大 200 × 200,
-- 讓它在手機上能放在金幣計數器與下方按鈕之間
local square = Instance.new("UIAspectRatioConstraint")
square.Parent = clickButton
local maxSize = Instance.new("UISizeConstraint")
maxSize.MaxSize = Vector2.new(200, 200)
maxSize.Parent = clickButton
local upgradeButton = newButton(gui, "", UDim2.new(0.5, -110, 1, -60), UDim2.fromOffset(200, 56), Color3.fromRGB(40, 150, 90))
local rebirthButton = newButton(gui, "", UDim2.new(0.5, 110, 1, -60), UDim2.fromOffset(200, 56), Color3.fromRGB(200, 90, 40))
local status = Instance.new("TextLabel")
status.AnchorPoint = Vector2.new(0.5, 1)
status.Position = UDim2.new(0.5, 0, 1, -96)
status.Size = UDim2.fromOffset(480, 28)
status.BackgroundTransparency = 1
status.TextColor3 = Color3.new(1, 1, 1)
status.FontFace = BOLD
status.TextSize = 20
status.Text = ""
status.Parent = gui
gui.Parent = player:WaitForChild("PlayerGui")
local function powerLevel(): number
local level = player:GetAttribute("PowerLevel")
return if type(level) == "number" then level else 1
end
local function update()
coinsLabel.Text = `{short(coins.Value)} coins`
local level = powerLevel()
upgradeButton.Text = if level >= Config.MAX_POWER_LEVEL
then "Click Power maxed"
else `Upgrade: {short(Config.upgradeCost(level))}`
rebirthButton.Text = `Rebirth: {short(Config.rebirthCost(rebirths.Value))}`
end
coins.Changed:Connect(update)
rebirths.Changed:Connect(update)
player:GetAttributeChangedSignal("PowerLevel"):Connect(update)
update()
-- 在按鈕上方彈出的「+N」。這個數字只是為了好看的估計;
-- 點擊實際值多少由伺服器決定。
local function popUp()
local pop = Instance.new("TextLabel")
pop.AnchorPoint = Vector2.new(0.5, 0.5)
pop.Position = UDim2.fromScale(0.5 + (math.random() - 0.5) * 0.1, 0.42)
pop.Size = UDim2.fromOffset(120, 40)
pop.BackgroundTransparency = 1
pop.TextColor3 = Color3.fromRGB(255, 214, 90)
pop.FontFace = BOLD
pop.TextScaled = true
pop.Text = `+{short(Config.clickValue(powerLevel(), rebirths.Value))}`
pop.Parent = gui
local tween = TweenService:Create(pop, TweenInfo.new(0.6), {
Position = pop.Position - UDim2.fromOffset(0, 60),
TextTransparency = 1,
})
tween.Completed:Once(function()
pop:Destroy()
end)
tween:Play()
end
clickButton.Activated:Connect(function()
clickEvent:FireServer()
popUp()
end)
local function ask(remote: RemoteFunction)
local ok, success, message = pcall(function()
return remote:InvokeServer()
end)
status.Text = if ok and type(message) == "string" then message else "No answer from the server. Try again."
status.TextColor3 = if ok and success == true then Color3.fromRGB(120, 220, 150) else Color3.new(1, 1, 1)
end
upgradeButton.Activated:Connect(function()
ask(buyUpgrade)
end)
rebirthButton.Activated:Connect(function()
ask(rebirthRemote)
end)
按鈕使用 Activated,Roblox 會在電腦上按滑鼠左鍵、手機上觸控,以及手把在 UI 導覽模式下按 A(或叉叉鍵)時觸發它。
在手把上,A 只會按下目前選取的按鈕。GuiService.AutoSelectGuiEnabled 開啟時,手把上的 Select 鍵會選取你的畫面按鈕;之後玩家可以在按鈕之間移動並按 A。如果想讓某個手把按鍵直接點擊,請透過 ContextActionService 綁定它,並從它呼叫同一個 Click remote。
Script 中的四個細節:
- Click 按鈕會依螢幕縮放。它的大小是螢幕的比例,
UIAspectRatioConstraint讓它保持正方形,UISizeConstraint把它限制在 200 × 200 像素。在螢幕上它寬 200 像素;在手機上它會縮小,放進金幣計數器與下方按鈕之間。如果你移動元素,請讓它和它們保持距離:Rebirth 沒有確認步驟,所以不小心碰到可能會重設玩家的金幣與升級。 - 彈出的「+N」只是為了好看。它使用用戶端那份公式。如果伺服器因為頻率限制忽略了一次點擊,「+N」還是會出現,但金幣不會改變。
short()讓大數字容易閱讀。1,234 會顯示為 1.2K,5,600,000 顯示為 5.6M。這個函式無條件捨去,所以計數器永遠不會顯示比你擁有的還多。超過 T(兆)的數字,請在UNITS中加入項目。- 畫面依事件更新。它監聽 Coins 與 Rebirths 數值以及 PowerLevel 屬性,所以不管數值怎麼變,按鈕上的價格都是正確的。
ScreenGui 的 ResetOnSpawn 設為 false,所以角色重生時它會留著。這在這裡很重要:StarterPlayerScripts 中的 LocalScript 只會在玩家進入時複製給他一次,所以它不會重新組出畫面。
步驟 4:透過 PlayerData 儲存進度
目前玩家離開時一切都會重設。模擬器不用第二個儲存 Script,而是接上DataStore 教學中的 PlayerData 模組。這個模組已經會重試失敗的請求、每 180 秒自動儲存、在玩家離開與伺服器關閉時儲存,而且永遠不會儲存資料沒有載入成功的玩家。
- 照著DataStore 教學的步驟 1,把 ModuleScript
PlayerData加到 ServerScriptService。要在 Studio 中測試儲存,請在遊戲的測試副本中開啟 Studio 的 API 服務存取權,方法在它的第一節中說明。SimulatorService 會自己用 require 載入模組,所以這裡不需要教學中的MainScript。 - 在 PlayerData 中,把
PowerLevel = 1,與Rebirths = 0,加到DEFAULTS表中,放在Coins = 0,旁邊。 - 在同一個模組中,把
PowerLevel: number,與Rebirths: number,加到Data型別中,讓嚴格型別檢查知道新的欄位。 - 在 SimulatorService 中,把
local SAVE_PROGRESS = false換成local SAVE_PROGRESS = true。
在你加入欄位之前就已經儲存過的玩家,會自動得到這些欄位:PlayerData 中的 migrate 函式會補上已儲存表中缺少的所有 DEFAULTS 欄位,所以他們會從 Click Power 等級 1 與 0 次重生開始,並保留自己的 Coins。如果你跳過第 2 項,SimulatorService 會印出警告列出需要加入的欄位,並且不會讓玩家開始。
為什麼模擬器直接寫入 PlayerData 的表
開啟儲存後,SimulatorService 不會把數值複製到任何地方。PlayerData.Get(player) 回傳模組儲存的那張即時表,模擬器就在這同一張表中修改 Coins、PowerLevel 與 Rebirths。每個數值只有一份,也只有一個 Script 寫入資料儲存區。兩個儲存同一個鍵的 Script 會互相覆蓋,其中一個可能會把舊數值存到另一個的數值上面。
不要像 DataStore 教學為其他遊戲建議的那樣,也在 Loaded 處理函式中建立 leaderstats:SimulatorService 已經從載入的表建立 Coins 與 Rebirths。如果排行榜 Script 已經在建立 leaderstats,請刪除它。
為什麼不在每次點擊時儲存
Roblox 允許每個伺服器每分鐘對一般資料儲存區寫入 60 + 40 × 玩家數 次(其餘限制在 DataStore 教學的限制表中)。以每秒 15 次點擊來說,每次點擊都儲存就是每位玩家每分鐘 900 次寫入,遠超過只有一位玩家的伺服器能得到的 100 次。每 180 秒、玩家離開時與伺服器關閉時儲存整張表,每位玩家只需要幾次寫入,當機時最多只會失去上次自動儲存之後的進度。
如果載入失敗,模組會讓玩家用新的數值遊玩,但永遠不會儲存它們,所以失敗的載入不可能覆蓋真正的進度。教學說明了模組如何處理這種情況。
為什麼每個數值都由伺服器決定
外掛使用者控制著自己的裝置。Roblox 的安全指南說,他們可以修改自己本機遊戲副本中的任何東西,並用任何引數呼叫任何 RemoteEvent 或 RemoteFunction 任意次數。模擬器的經濟系統安全的程度,完全取決於它的伺服器 Script 安全的程度。
| 外掛使用者嘗試 | 如果由用戶端決定 | SimulatorService 的處理 |
|---|---|---|
| 用迴圈以最快速度呼叫 Click | 無限金幣 | 每個一秒時間窗最多採計 15 次點擊,其餘忽略。 |
| 連同點擊一起傳送金幣數量 | 他自己決定獎勵 | 忽略所有引數。點擊的價值取自伺服器的數值。 |
| 沒有足夠金幣就購買升級或重生 | 免費升級 | 把價格和伺服器上的 Coins 比對,並回覆 "You need N more coins." |
| 在自己的畫面上修改 leaderstats 中的 Coins | 花掉他沒有的金幣 | 從不讀取 leaderstats。它只從自己的表寫入那裡。 |
| 在自己的 Player 上設定 PowerLevel 屬性 | 更強的點擊 | 從不讀取這個屬性,而且變更只會留在玩家的裝置上。 |
| 同一時間呼叫 Rebirth 兩次 | 用一次的價格重生兩次 | 每次呼叫都重新檢查價格,而且在檢查與變更之間不會讓出執行。 |
| 修改自己那份 SimulatorConfig 中的價格 | 更便宜的升級 | 使用它自己那份模組。 |
這條規則適用於模擬器中的每個 remote:傳送玩家想做什麼,而不是它值多少。RemoteEvent 教學更詳細地說明如何檢查 remote 的引數。
複製來的點擊遊戲 Script 中要避免什麼
| 做法 | 問題 | 本教學 |
|---|---|---|
LocalScript 用 leaderstats.Coins.Value += 1 加金幣 | 變更只留在一台裝置上,而那台裝置由外掛使用者控制 | 由伺服器加金幣 |
clickEvent:FireServer(amount) | 用戶端自己決定獎勵 | Click 不傳任何引數 |
| 伺服器上沒有頻率限制 | Roblox 文件說絕對不要只依賴用戶端的限制 | 每個一秒時間窗最多 15 次點擊 |
每次點擊或升級都 SetAsync | 吃光伺服器的寫入額度 | PlayerData 每 180 秒、離開時與關閉時儲存。只有在不能遺失的事情之後,例如 Robux 購買,才用 PlayerData.SaveNow 立即儲存。 |
| 只給模擬器用的第二個資料儲存 Script | 兩個儲存同一個鍵的 Script 會互相覆蓋 | 寫入 PlayerData 的表 |
用 while wait(1) do 迴圈做被動收入 | Roblox 把全域的 wait 標為已淘汰,由 task.wait 取代 | task.wait(請見如何擴充) |
按鈕上的 MouseButton1Click | 是為滑鼠點擊設計的 | Activated,適用滑鼠、觸控與手把 |
步驟 5:測試
在 SimulatorService 中設定 SAVE_PROGRESS = false 來進行第 1 到 8 項,讓每次試玩測試都從新的數值開始。如果你已經在步驟 4 開啟儲存,暫時把它設為 false,到第 9 項再改回 true。
- 按 Play。畫面上方寫著 0 coins,綠色按鈕上是 Upgrade: 10,橘色按鈕上是 Rebirth: 1.0K。
- 按紫色的 Click! 按鈕十次。每次點擊都會出現金色的 +1,玩家清單中的 Coins 增加 1。
- 按 Upgrade。金幣回到 0,狀態列變成綠色並顯示 "Click Power is now level 2.",按鈕現在是 Upgrade: 15。從這時起,每次點擊給 2 金幣。
- 不要點擊,直接按 Rebirth。狀態列顯示 "You need 1000 more coins to rebirth.",什麼都沒有改變。
- 要在不點 1,000 下的情況下測試重生,請停止測試,在 SimulatorService 結尾附近讓新玩家開始的那一行,把
Coins = 0改成Coins = 1000,然後按 Play。按 Rebirth:Coins 變成 0,玩家清單中的 Rebirths 變成 1,狀態列顯示 "Rebirth 1! Every click is now worth x2.",按鈕現在是 Rebirth: 3.0K。在 Click Power 等級 1 時,每次點擊現在給 2 金幣。之後把那一行改回 0。 - 要看到頻率限制,把 SimulatorConfig 中的
MAX_CLICKS_PER_SECOND設為 2 並快速點擊。「+N」會繼續出現,但 Coins 每秒最多只增加 2 次點擊的價值。改回 15。 - 在 Studio 的 Device Simulator 中選一支手機(它是 Studio 的 beta;舊版的 Device Emulator 也可以)並按 Play。確認 Click 按鈕沒有蓋到金幣計數器,也沒有蓋到 Upgrade 與 Rebirth 按鈕,而且按 Upgrade 時狀態列看得到、沒有被按鈕擋住。
- 在試玩測試中接上手把,或打開 Studio 的 Controller Emulator(Emulation 分頁中的 Controller),按 Select,確認三個按鈕都能選到,並能用 A 按下。
- 開啟儲存(步驟 4)並再次設為
SAVE_PROGRESS = true,賺一些金幣,按 Stop,再按一次 Play。你的 Coins、Click Power 等級與 Rebirths 都會回來。
製作健身房或礦場模擬器
許多模擬器把按鈕換成世界中的動作:舉啞鈴、揮鎬子、在空中揮劍。底下還是同樣的點擊。Tool 可以呼叫同一個 Click remote,所以 SimulatorService、它的價格與它的頻率限制都維持不變。
- 在 Explorer 中把游標移到 StarterPack 上,插入一個 Tool 並命名為
Dumbbell。在裡面插入一個名為Handle的 Part,把它做成啞鈴的形狀並取消勾選 Anchored,就像劍教學中製作 Tool 的步驟那樣。 - 在 Tool 中插入一個名為
LiftClient的 LocalScript,並貼上下面的程式碼。 - 按 Play,拿起啞鈴並點擊。每舉一次,金幣就增加你的 Click Power,和按鈕完全一樣。
-- 放在 Tool Dumbbell 中、名為 LiftClient 的 LocalScript。
-- 每舉一次就是一次點擊:它呼叫和按鈕相同的 Click remote,由伺服器
-- 決定它值多少,以及要採計幾次舉起。
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local tool = script.Parent :: Tool
local remotes = ReplicatedStorage:WaitForChild("SimulatorRemotes")
local clickEvent = remotes:WaitForChild("Click") :: RemoteEvent
local LIFT_SECONDS = 0.5 -- 這台裝置上兩次舉起之間的時間;伺服器有自己的限制
local LIFT_ANIMATION_ID = "" -- 選用:"rbxassetid://" 後面接你的動畫 id
local player = Players.LocalPlayer
local lastLift = 0
local liftTrack: AnimationTrack? = nil
local trackCharacter: Model? = nil
-- 每個角色載入一次舉起動畫,透過 Roblox 放在 Humanoid 中的 Animator
local function loadLift()
local character = player.Character
if LIFT_ANIMATION_ID == "" or not character or character == trackCharacter then
return
end
local humanoid = character:FindFirstChildOfClass("Humanoid")
local animator = humanoid and humanoid:FindFirstChildOfClass("Animator")
if animator then
local animation = Instance.new("Animation")
animation.AnimationId = LIFT_ANIMATION_ID
liftTrack = animator:LoadAnimation(animation)
trackCharacter = character
end
end
tool.Equipped:Connect(loadLift)
tool.Activated:Connect(function()
local now = os.clock()
if now - lastLift < LIFT_SECONDS then
return
end
lastLift = now
if liftTrack then
liftTrack:Play()
end
clickEvent:FireServer() -- 沒有引數:獎勵由伺服器計算
end)
舉起動畫請在 Animation Editor 中製作,優先順序設為 Action,發布後把它的 ID 貼到 LIFT_ANIMATION_ID。劍教學中的動畫步驟做法相同。
- 讓伺服器限制配合動作。
LIFT_SECONDS只會讓正常玩家慢下來:作弊者可以從自己的程式碼呼叫 Click。如果舉啞鈴是唯一的賺錢方式,請把 SimulatorConfig 中的MAX_CLICKS_PER_SECOND降到實際的節奏,例如每 0.5 秒舉一次就設為 2,讓 Script 賺得不會比玩家多。之後重新計算節奏表:裡面的每個時間都是以每秒 5 次點擊計算的。 - 保留或隱藏按鈕。Click 按鈕在 Tool 旁邊仍然可以用。要隱藏它,請在 SimulatorClient 中建立
clickButton的那一行之後,緊接著加上clickButton.Visible = false。 - 只在對的地方賺錢。如果只想在健身房或礦場中給錢,請在伺服器上採計點擊前檢查角色的位置,例如計算到該區域中某個零件的距離。在 LiftClient 中檢查擋不住任何人。
接下來做什麼:模擬器的製作順序
模擬器是疊在這個循環上的一層層系統。照這個順序製作,讓每個系統都有東西可以加乘,並在每一個之後做試玩測試。這是我們建議的順序,每一步都附上教學。
| 順序 | 系統 | 教學 | 為什麼是現在 |
|---|---|---|---|
| 1 | 賺錢、升級、重生 | 本教學 | 其他所有東西都是在加乘這個循環,所以先依節奏表調好它的數值。 |
| 2 | 儲存 | DataStore 教學,接著步驟 4 | 重新進入就重設的進度會毀掉模擬器。在加入任何玩家會失去的東西之前先加上它。 |
| 3 | 當作倍率的蛋與寵物 | 孵蛋與跟著玩家的寵物 | 金幣以外的第二個目標:可以收集、並讓每次點擊更值錢的東西。 |
| 4 | 重生解鎖的區域 | 如何擴充 | 重生後要去的地方,有更好的獎勵,由伺服器檢查。 |
| 5 | 排行榜 | 排行榜教學 | 依重生次數排名的全域前 10 名,讓漫長的爬升有意義。 |
| 6 | 每日獎勵與兌換碼 | 每日獎勵與兌換碼 | 讓玩家明天以及每次更新後回來的理由。 |
| 7 | 遊戲通行證 | 遊戲通行證教學 | 2 倍金幣、自動點擊或多一個寵物欄位,由伺服器檢查。等免費的循環已經好玩了再販售它們。 |
畫面方面,免費的Roblox UI 套件包含模擬器風格的畫面,以及讓它們運作的 Script。
不寫 Script 怎麼做模擬器
模擬器還是需要 Script:總要有東西負責加金幣、檢查價格和儲存。但不一定要自己寫:
- Creator Store 的模擬器套件。發布前先讀過它的 Script,確認金幣只在伺服器 Script 中改變,而不是在 LocalScript 中。
- 模擬器產生器外掛程式。對它建立的所有東西做同樣的檢查。
- Studio 中的 AI 代理,例如 RoCode,可以在你開啟的場景中組出同樣這三個 Script。
- Roblox 手機 App 中的 Build。根據 Roblox 文件,它能依描述做出較簡單的 2D 與 2.5D 遊戲,例如點擊遊戲,並正逐步在各地區推出。
不管選哪一種,都請對結果進行步驟 5的測試,以及為什麼每個數值都由伺服器決定一節中的外掛檢查。
如何擴充:寵物、區域、自動點擊與排行榜
當作倍率的寵物
常見的做法:每隻寵物都是一個倍率。把玩家的寵物 id 清單存在他已儲存的表中,讓伺服器把 clickValue 乘上每隻裝備中寵物的加成。在伺服器上孵蛋:用戶端請求孵蛋,伺服器檢查並扣除價格,再用加權隨機抽出寵物。絕對不要讓用戶端替蛋擲骰,或說出抽到哪隻寵物。背包教學說明如何保存、儲存與顯示玩家的物品,寵物的做法也一樣。孵蛋教學在伺服器上做出抽獎,寵物教學讓寵物飛在主人身邊。
靠重生解鎖的區域
區域是地圖中一塊在障礙後面、獎勵更好的地方。要鎖住的是獎勵,而不只是門:區域內所有會給錢的東西,在給錢之前都必須檢查伺服器表中玩家的 Rebirths。由 LocalScript 替符合資格的玩家打開的門可以拿來做外觀,但外掛使用者可以在自己的裝置上修改零件並移動自己的角色。
把自動點擊做成遊戲通行證
當作遊戲通行證販售的自動點擊必須在伺服器上執行。把 Click 處理函式的內容移到一個函式中,例如 addClick(player),讓 remote 呼叫它,並替擁有通行證的玩家從伺服器迴圈中以 task.wait(0.5) 呼叫它,而不是用已淘汰的 wait。這樣自動點擊就會計入和一般點擊相同的每秒限制。像遊戲通行證教學處理它的福利那樣,在伺服器上用 MarketplaceService:UserOwnsGamePassAsync 檢查擁有權。2 倍金幣通行證的做法也一樣:在伺服器上替擁有者把 clickValue 加倍。定價之前,免費的Robux 稅金計算機會告訴你扣掉 Roblox 的分成後每筆銷售能拿到多少,DevEx 計算機則會告訴你這些 Robux 值多少美元。
依重生次數的全域前 10 名
leaderstats 只比較同一個伺服器上的玩家。要為所有玩家的 Rebirths 排名,請把它們寫入有序資料儲存區(ordered data store)並讀回最上面的項目,就像排行榜教學的步驟 4那樣。有序儲存區允許的寫入次數比一般儲存區少,每個伺服器每分鐘 30 + 5 × 玩家數 次,所以請在玩家離開時與依計時器寫入。
非常大的數字
Luau 中的數字是 double,大約保存 15 位有效數字。IntValue 保存的整數大約到 9.2 百京(quintillion),但 Roblox 警告,大於 2^53(大約 9 千兆)的數值在 Script 中會失去精確度。以這些設定,重生價格會在第 29 次重生時超過這個門檻。如果你的遊戲會走得更遠,請把 leaderstats 的數值改成 NumberValue(在兩個 Script 中都替換 IntValue),它能保存大得多的數字,精確度一樣大約 15 位,並在 short() 中加入後綴。
模擬器遊戲靠什麼撐起來
模擬器是數字的遊戲。上面的點擊、升級與重生就是整個循環;玩家會不會留下來,取決於這些數字怎麼成長。每隔幾分鐘,玩家都應該能買得起某樣讓接下來幾分鐘更快的東西,而每次遊玩都應該結束在一個讓人想回來達成的目標附近。
- 撐得夠久的成長。升級價格成長得比收入快,所以每一階都要多花一點時間。重生為了永久倍率而重設金幣,舊區域變得很快,爬升也感覺煥然一新。
- 可以收集的東西。要解鎖的區域、會加乘收入的蛋中的寵物,以及可以升級的工具,讓玩家在單一數字之外還有一串目標。
- 保持容易閱讀的大數字。顯示 1.5M 而不是 1500000,並用讓伺服器即使數字變大也能比較的方式保存數字。
適合模擬器的營利方式
常見的通行證會加乘金幣、多給一個寵物欄位、一次孵更多顆蛋,或開啟自動點擊。把它們當作遊戲通行證販售,並在伺服器上檢查。金幣包是 developer product。如果蛋或任何隨機結果的東西可以用 Robux 或用 Robux 買來的貨幣購買,Roblox 要求在購買前顯示機率:製作商店前請先閱讀 paid random items(英文)。
什麼會讓玩家回來
已儲存的進度、更新中的新區域或新寵物組合、每日獎勵、隨更新一起公布的兌換碼,以及依重生次數的排行榜。其他類型各有自己的循環、系統與製作計畫:Roblox 遊戲類型。
常見錯誤與解法
按 Play 之前先打開 Output 視窗(Window 選單,然後 Output)。大多數問題都會在那裡印出帶有 Script 名稱與行號的警告或錯誤。
Infinite yield possible on 'ReplicatedStorage:WaitForChild("SimulatorRemotes")'
LocalScript 在等 SimulatorService 於開始時建立的 remote。確認 SimulatorService 是 Script 而不是 LocalScript,放在 ServerScriptService 中,而且 Output 中沒有它的錯誤。如果 SimulatorConfig 出現同樣的警告,代表 ReplicatedStorage 中沒有這個模組,或名稱不一樣。
按鈕一直沒有出現
LocalScript 會等你的 leaderstats 出現後才組出畫面。如果 Output 中針對 leaderstats 寫著 Infinite yield possible,代表 SimulatorService 還沒讓你開始。SAVE_PROGRESS = true 時它會等 PlayerData,所以請確認 PlayerData 放在 ServerScriptService 中,而且載入時沒有錯誤。
Output 中寫著 "SimulatorService: add PowerLevel = 1 and Rebirths = 0 to DEFAULTS in the PlayerData module"
儲存已經開啟,但 PlayerData 模組中還沒有新的欄位。像步驟 4那樣把它們加到它的 DEFAULTS 中,再按一次 Play。
「+1」有彈出來,但金幣沒有增加
伺服器沒有採計點擊。可能是 SimulatorService 出錯(在 Output 中找它的紅字),或是點擊來得比 MAX_CLICKS_PER_SECOND 允許的還快。如果玩家在正常遊玩時就碰到上限,請在 SimulatorConfig 中調高它。
狀態列顯示 "No answer from the server. Try again."
BuyUpgrade 或 Rebirth 的呼叫失敗了,而不是回傳了回覆。常見原因是 SimulatorService 在處理請求時出錯,所以請在 Output 中找它的紅色錯誤:裡面會寫出是哪一行。
畫面上的金幣計數器和玩家清單顯示不同的數字
還有另一個 Script 也在建立 leaderstats 資料夾,所以每位玩家有兩個,LocalScript 可能讀到另一個。請刪除多餘的 Script:SimulatorService 會自己建立 Coins 與 Rebirths。
每次重新進入金幣都會重設
儲存是關閉的。請完成步驟 4。如果已經開啟,但金幣在 Studio 中還是會重設,請確認測試副本中已開啟 Studio 的 API 服務存取權,如 DataStore 教學所說明。
用 RoCode 來做
如果不想手動貼上這些,RoCode 可以在你開啟的場景中把它組好。它是獨立的程式設計 AI 代理,不是 Roblox 官方的:你在它的網頁聊天中描述系統,它的 Roblox Studio 外掛程式就會在你的 Explorer 中建立 Script,所以不需要從聊天視窗複製程式碼。
做一個點擊模擬器:一個大的 Click 按鈕,給的金幣等於我的 Click Power 等級乘以(重生次數 + 1),一個 Upgrade 按鈕,價格 10 金幣,每升一級貴 1.5 倍,以及一個 1,000 金幣的 Rebirth 按鈕,會重設金幣與升級。數值放在伺服器上,點擊限制為每秒 15 次。我已經有 PlayerData 模組了。
- 可以先透過 Search Scripts 與 Read Script 讀取你的 PlayerData 模組與任何 leaderstats Script,把欄位加到你現有的資料中,而不是寫第二個儲存 Script
- 可以透過 Build UI 的 HUD 版面(外掛程式 3.9 或更新版本,模擬器風格)做出畫面的雛形,或在 LocalScript 中組出按鈕,並透過 Create Script 寫出 ModuleScript、伺服器 Script 與 LocalScript
- 它被要求用 Check Script 檢查寫出的每個 Script 能否編譯,Check Script 會在 Studio 中編譯而不執行它
- 在每一批變更前後設定復原點,所以 Ctrl+Z 一次復原一批
RoCode 無法建立遊戲通行證與 developer product,也無法上傳網格或寵物圖示:這些要在 Creator Hub 與 Studio 中完成。使用外掛程式 3.9.11 或更新版本,RoCode 可以在 Studio 中執行你遊戲的試玩測試,並操控測試角色確認一切正常;使用外掛程式 3.9.15 或更新版本,測試角色還可以按畫面按鈕,例如按 Click 並確認 Coins 增加了。它會自己決定何時執行試玩測試,每次建置最多 2 次,再加 1 次用來檢查自己的修正,而且只檢查它選擇的項目,所以循環請自己測試。一整個模擬器需要好幾個提示詞,一次一個系統:如何用 RoCode 一個提示詞做一個系統。RoCode 如何連接 Studio。
常見問題
不寫 Script 要怎麼在 Roblox 做模擬器?
能運作的模擬器需要 Script:總要有東西負責加金幣、檢查價格和儲存進度。你可以把本教學的三個 Script 原樣貼上,只修改 SimulatorConfig 中的數值,或交給 Creator Store 的套件、外掛程式或 AI 代理製作,再確認金幣由伺服器決定。各種做法。
重生系統是怎麼運作的?
重生把你的金幣與升級換成永久加成。在本教學中,第一次重生需要 1,000 金幣;它把 Coins 設為 0、Click Power 設為等級 1,並把 Rebirths 加 1,之後每次點擊都乘以 Rebirths + 1。每次重生的價格是前一次的三倍。
要怎麼做力量或健身房模擬器?
給玩家一個 Tool,例如啞鈴,它的 LocalScript 在 Tool.Activated 時呼叫同一個 Click remote。伺服器計算獎勵的方式和按鈕點擊完全一樣。把伺服器的點擊上限降到舉起的節奏,讓 Script 賺得不會比玩家多。Script 在啞鈴版本一節。
模擬器需要哪些系統?
先是賺錢、升級與重生的循環,接著是儲存,然後是寵物或其他會加乘收入的收集要素、重生解鎖的區域、排行榜、每日獎勵與兌換碼,最後才是遊戲通行證。製作順序中每一項都附有教學。
一次重生應該要多久?
要久到讓玩家先買幾次升級,也要短到第一次遊玩就能達成一次。以本教學的數值,每秒點 5 下大約 1.2 分鐘就能第一次重生;如果把 REBIRTH_BASE_COST 調高到 10,000,大約要 8 分鐘。更多設定請見節奏表。
要怎麼防止連點器?
伺服器在每個一秒時間窗中,每位玩家最多採計 15 次點擊,其餘忽略。在這個上限以下,Script 看起來就跟手很快的玩家一樣,所以保護經濟系統的正是這個上限。你也可以把在伺服器上執行的自動點擊當作遊戲通行證販售。
為什麼重新進入後金幣會重設?
目前還沒有任何東西在儲存它們。加入 DataStore 教學中的 PlayerData 模組,把 PowerLevel 與 Rebirths 加到它的 DEFAULTS 中,並在 SimulatorService 中設定 SAVE_PROGRESS = true,就像步驟 4 那樣。
要怎麼在模擬器中加入寵物?
讓每隻寵物都成為伺服器套用到點擊上的倍率。在伺服器上用加權隨機的方式孵蛋,把玩家的寵物 id 和他的其他資料一起儲存,並在背包 GUI 中顯示它們,就像背包教學那樣。
點零件好還是點按鈕好?
兩種都可以。畫面按鈕在手機上很方便,有 ClickDetector 的零件則適合一切都發生在世界中的遊戲。根據 Roblox 文件,伺服器完全不會檢查 ClickDetector 事件,所以請用同樣的方式在伺服器上限制這些點擊的頻率。
來源與延伸閱讀
- Roblox Creator Docs:Securing the client-server boundary(英文). 頻率限制、遊戲內商店範例與 ClickDetector 事件
- Roblox Creator Docs:Security and cheat mitigation tactics(英文). 外掛使用者在自己的裝置上能控制什麼
- Roblox Creator Docs:Remote events and callbacks(英文). FireServer、玩家參數、InvokeServer 與 OnServerInvoke
- Roblox Creator Docs:Leaderboards(英文). leaderstats 與有序資料儲存區
- Roblox Creator Docs:Data store error codes and limits(英文). 一般與有序資料儲存區每個伺服器的寫入限制
- Roblox Engine API:GuiButton(英文). 電腦、手機與主機上的 Activated
- Roblox Engine API:GuiService(英文). AutoSelectGuiEnabled 與用手把選取 GUI 物件
- Roblox Engine API:IntValue(英文). 64 位元範圍,以及超過 2^53 後失去精確度
- Roblox Creator Docs:Size modifiers and constraints(英文). UIAspectRatioConstraint 與 UISizeConstraint
- Roblox Creator Docs:Studio testing modes(英文). Device Simulator 與 Controller Emulator
程式碼如何驗證:本頁每一段 Script 都通過 Luau 嚴格型別檢查,並使用 Roblox API 定義(luau-lsp,2026年11月20日)。型別檢查能找出拼錯的 API 與錯誤的型別,但無法檢查遊戲邏輯,所以發布前請先在 Studio 中測試。