所以我试图将文本始终设置为数字值,但它不起作用。
这是我的问题代码...
while true do
wait(0.2)
script.Parent.Text = script.Parent.Parent.Amount.Value
end
我期待文本显示数字值,但它没有。
由于这是在您的 UI 中,请确保您使用的是 LocalScript 而不是脚本。
实现此目的的一个好方法是在 NumberValue 上使用 Changed 信号。每次值发生变化时,它都会触发连接的函数,因此您可以轻松保持文本属性与 NumberValue 的值同步。但是,由于该值是数字,因此请务必使用
tostring
函数将其转换为字符串。
所以试试这个:
local numberValue = script.Parent.Parent.Amount
local label = script.Parent
-- create a helper function to update the text
function updateText()
label.Text = tostring(numberValue.Value)
end
-- set the text for the first time
updateText()
-- update the text every time the number changes
numberValue.Changed:Connect(updateText)
你需要一个“BoolValue”来更新金额,如果你希望它顺利,那么我不是要问的人。