尝试制作硬币计数器,测试时没有反应

所以,我正在开发 Roblox 上的一个游戏,并且我正在尝试制作一个硬币计数器。基本上,当硬币被收集时,StarterPlayer 中的 NumberValue 会+1。然后,TextLabel 将循环检查 NumberValue 的值。然后它将更改文本以显示 NumberValue 的值。 然而,当我进行测试时,什么都没有发生。计数器不会改变,但 NumberValue 会改变。 以下是 Coin 的代码:

local coin = script.Parent
local sp = game:GetService("StarterPlayer")
local count = sp.Coins
local p = game:GetService("Players")
local Touched = false

coin.Touched:Connect(function()
    count.Value += 1
    local Sparkles = Instance.new("Sparkles")
    Sparkles.Parent = coin
    Sparkles.SparkleColor = Color3.fromRGB(255, 255, 0)
    wait(2)
    count.Value += 1
    coin:Destroy()
end)

以及 TextLabel 的代码:

local StarterPlayer = game:GetService("StarterPlayer")
local Coins = StarterPlayer.Coins
local CoinLabel = script.Parent

while true do
    CoinLabel.Text = Coins.Value
end

有人知道如何解决这个问题吗?

点赞