Lua 刷新脚本(ROBLOX)

我正在创建一个 ROBLOX 中的 GUI 界面。该 GUI 用于显示玩家的货币数量,但是当我测试并尝试更新玩家的货币数量时,GUI 却没有随之更新。我添加了一个旧代码,因为在我之前在不同语言工作的一个旧项目中它能够正常工作。我当时并不知道自己在想些什么。

下面是代码:

local player = game.Players.LocalPlayer
coinAmount = player:WaitForChild("leaderstats"):WaitForChild("Coins")
oldCoinAmount = player:WaitForChild("leaderstats"):WaitForChild("Coins")
text = script.Parent

if coinAmount ~= oldCoinAmount then
    text = oldCoinAmount
end

我想也许有一种方法可以不断刷新脚本,但我不知道怎么做。

另外,这个 LocalScript 是实际 GUI 的子级,它也没有抛出任何错误。

点赞
用户12488192
用户12488192

我已经想通了,如果你想要做这个,你可以使用下面这个脚本:

local player = game.Players.LocalPlayer
coinAmount = player:WaitForChild("leaderstats"):WaitForChild("Coins")
text = script.Parent

coinAmount.Changed:connect(function()
    text.Text = coinAmount.Value .. " Coins"
end)
2020-03-21 19:23:46