Lua刷新脚本(ROBLOX)
Lua Refreshing Script (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 的子项
它也不会抛出任何错误。
我明白了,如果你想这样做,你可以使用这个脚本:
local player = game.Players.LocalPlayer
coinAmount = player:WaitForChild("leaderstats"):WaitForChild("Coins")
text = script.Parent
coinAmount.Changed:connect(function()
text.Text = coinAmount.Value .. " Coins"
end)
我正致力于在 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 的子项 它也不会抛出任何错误。
我明白了,如果你想这样做,你可以使用这个脚本:
local player = game.Players.LocalPlayer
coinAmount = player:WaitForChild("leaderstats"):WaitForChild("Coins")
text = script.Parent
coinAmount.Changed:connect(function()
text.Text = coinAmount.Value .. " Coins"
end)