【问题标题】:How to change text on tool activated?如何更改激活工具上的文本?
【发布时间】:2022-01-29 13:39:44
【问题描述】:

我再次在 Roblox 中,我想制作一个脚本,当我的工具被激活时,它会在我的文本标签中添加 1。示例:如果文本标签为零,则激活工具,将其更改为 1,如果为 1,则变为 2,依此类推。这是我的脚本:

script.Parent.Activated:Connect(function()
    game.Players.LocalPlayer.PlayerGui.ScreenGui.cashcount.Text = game.Players.LocalPlayer.PlayerGui.ScreenGui.cashcount.Text + 1
end)

【问题讨论】:

  • 当您提出问题时,您应该详细说明问题所在和/或您收到的错误消息。
  • 既然你不说出了什么问题,那就有点难以猜测了。但您似乎正在尝试将整数添加到字符串中。在Lua中不能这样做。也许可以试试a = tonumber(game.Players.LocalPlayer.PlayerGui.ScreenGui.cashcount.Text)a=a+1game.Players.LocalPlayer.PlayerGui.ScreenGui.cashcount.Text = a

标签: lua roblox


【解决方案1】:

您的脚本不起作用的原因是您试图在文本中添加 +1,这就像问“1 加金星是什么?”创建一个变量,然后将文本设置为变量有效。 将此 LocalScript 放入工具中。

local cash = 0
script.Parent.Activated:Connect(function()
    cash+=1
    game.Players.LocalPlayer.PlayerGui.ScreenGui.cashcount.Text = tostring(cash)
end)

【讨论】:

  • 我已经用不同的方式解决了这个问题,但我觉得这更容易,所以谢谢
  • 如果对您有帮助,请将其标记为正确,以便其他人知道:)
猜你喜欢
  • 1970-01-01
  • 2021-05-31
  • 2021-05-24
  • 1970-01-01
  • 1970-01-01
  • 2015-01-24
  • 2021-09-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多