“Players.shaz:WaitForChild(“Values”)”上可能有无限的产量我试图做到这一点,以便当玩家认领摊位时,它会将 bool 值变为 true

发布于 2025-01-20 15:06:35 字数 375 浏览 2 评论 0原文

local claim = script.Parent.Parent.Parent.Parent.StandMesh.Claim

这将触发代理提示。

claim.Triggered:Connect(function(player)
local screengui = player.PlayerGui:WaitForChild('Popups')
local popup = player.PlayerGui:WaitForChild('Popups').ClaimedBooth
local bool = player:WaitForChild('Values').Claimed
local claim = script.Parent.Parent.Parent.Parent.StandMesh.Claim

This will trigger the Proximty Prompt.

claim.Triggered:Connect(function(player)
local screengui = player.PlayerGui:WaitForChild('Popups')
local popup = player.PlayerGui:WaitForChild('Popups').ClaimedBooth
local bool = player:WaitForChild('Values').Claimed

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹏半生如梦愿梦如真 2025-01-27 15:06:36

“无限收益可能”是一个警告。它让您知道您的代码不安全,并且在执行此代码时,value对象不存在(或不正确地拼写)超过5秒('values')无法解析到对象。

实例:waitforchild()要说:

注释

  • 如果对此功能的调用超过5秒而没有返回,并且没有指定超时参数,则将打印出螺纹可能无限期产生的输出的警告;此警告在'x:waitforchild(“ y”)'上可能会产生无限的收益,其中x是父母名称,y是子对象名称。
  • 如果呼叫时存在给定名称的孩子,则此功能不会产生。
  • 此功能效率不如实例:Findfirstchild或点运算符。因此,只有在开发人员不确定对象是否已复制给客户端时,才应使用它。通常,这只是对象第一次访问

您可以通过添加timeout作为第二个参数来删除此警告,但是您需要考虑以下事实:对象可能是对象' t找到:

local timeout = 2 -- seconds
local values = player:WaitForChild('Values', timeout)
if values then
    local boolVal = values.Claimed
    print("Claimed = ", boolVal.Value)
    -- mark it as claimed
    boolVal.Value = true
else
    warn("Could not find 'Values' BoolValue")
end

或者,如果您知道value将在该代码执行时存在,则可以使用点运算符或findfirstchild()函数访问它。 。但是,如果value不存在,这将引发“尝试索引无”错误。

local boolVal = player:FindFirstChild('Values').Claimed
-- or
local boolVal = player.Values.Claimed

-- mark it as claimed
boolVal.Value = true

当您看到此警告时,应仔细检查对象名称的拼写,以及脚本执行何时执行的时间,以确保对象实际存在。

"Infinite yield possible" is a warning. It lets you know that your code is unsafe, and that when this code executed, the Values object didn't exist (or was spelled incorrectly) for more than 5 seconds, and player:WaitForChild('Values') could not resolve to an object.

The documentation for Instance:WaitForChild() has this to say :

Notes

  • If a call to this function exceeds 5 seconds without returning, and no timeOut parameter has been specified, a warning will be printed to the output that the thread may yield indefinitely; this warning takes the form Infinite yield possible on 'X:WaitForChild("Y")', where X is the parent name and Y is the child object name.
  • This function does not yield if a child with the given name exists when the call is made.
  • This function is less efficient than Instance:FindFirstChild or the dot operator. Therefore, it should only be used when the developer is not sure if the object has replicated to the client. Generally this is only the first time the object is accessed

You can remove this warning by adding a timeout as a second argument, but you'll need to account for the fact that it's possible that the object isn't found :

local timeout = 2 -- seconds
local values = player:WaitForChild('Values', timeout)
if values then
    local boolVal = values.Claimed
    print("Claimed = ", boolVal.Value)
    -- mark it as claimed
    boolVal.Value = true
else
    warn("Could not find 'Values' BoolValue")
end

Alternatively, if you know that Values will exist at the time this code will execute, you can simply access it with the dot operator or with the FindFirstChild() function. But this will throw an "Attempt to index nil" error if Values doesn't exist.

local boolVal = player:FindFirstChild('Values').Claimed
-- or
local boolVal = player.Values.Claimed

-- mark it as claimed
boolVal.Value = true

When you see this warning, you should double check the spelling on the name of the object, as well as the timing of when the script executes to make sure that the object actually exists.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文