【问题标题】:Why Do I Get Function Errors In My Script?为什么我的脚本中出现函数错误?
【发布时间】:2019-06-23 04:26:47
【问题描述】:

我观看了有关如何在 Roblox 中制作捐赠按钮的 YouTube 视频,并按照步骤操作。但是当我使用它时,它给了我多个错误。

我尝试将.connect 更改为:Connect,但它给了我更多错误,我尝试将end) 更改为end,但它给了我更多错误。

代码:

local id = 459818680

script.Parent.TextButton.MouseButton1Click.connect()(function()
game:GetService("MarketplaceService"):PromptProductPurchase            
(game.Players.LocalPlayer, id)
end)

我希望在测试时能够单击它,然后会弹出购买菜单。没啥事儿。我也遇到了这样的错误:

Players.ImNotKevPlayz.PlayerGui.ScreenGui.LocalScript:4:“连接”的参数 #1 错误(预期为 RBXScriptSignal,没有值)

当我在 Roblox 命令中尝试调试命令时,它给了我这个错误:

脚本错误:'=' 应在 '' 附近

【问题讨论】:

  • 你能发布你遇到的错误吗?如果可以的话,也是代码的最小、完整和可验证的示例,如下所述:stackoverflow.com/help/mcve
  • 我确实包含了我得到的错误..
  • 你说它给了你错误,然后你改变了一些有更多错误的东西。我不记得你说过你做了什么错误。这就是我想说的:D
  • 当我将 .connect 更改为 :Connect Players.ImNotKevPlayz.PlayerGui.LocalScript:5: ambiguous syntax (function call x new statement) near '(' 以及当我再次尝试脚本时出现此错误做结束而不是结束)什么也没发生。我很确定 roblox 更新了他们的脚本,所以这个脚本可能已经过时了。我真的不知道。

标签: function roblox


【解决方案1】:

嘿嘿,您的脚本几乎可以运行,只是看起来您遇到了一些语法错误。

bad argument #1 to 'connect' (RBXScriptSignal expected, got no value)

这意味着 MouseButton1:Connect 函数期待一个参数,但你没有给它任何东西。

试试这个修复:

local id = 459818680
local targetButton = script.Parent.TextButton
local MarketplaceService = game:GetService("MarketplaceService")

targetButton.MouseButton1Click:Connect(function() --  <-- this just needed to be fixed
    local player = game.Players.LocalPlayer
    MarketplaceService:PromptProductPurchase(player, id)
end)

【讨论】:

  • 不,出现这些错误 TextButton is not a valid member of TextButton
  • 或此 TextButton 不是 ScreenGui 的有效成员
  • 对不起,我是新手,我真的不知道如何编辑东西。
  • 这个错误是指向本地targetButton的赋值吗?此脚本的假设是您已将此脚本作为某个对象的子对象,并且该对象中还有一个名为“TextButton”的 TextButton。您是否将 TextButton 重命名为其他名称?
  • 哦,我把名字改成了别的。
猜你喜欢
  • 2010-11-02
  • 1970-01-01
  • 2012-01-02
  • 2012-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-03
相关资源
最近更新 更多