如何修复Roblox无限产量错误?

<---这是我的当前本地脚本--->

本地复制存储 = 游戏:GetService(“复制存储”)
starterRebirthAmount = 5000

本地玩家= 游戏.Players.LocalPlayer
主要框架= 脚本.Parent:WaitForChild(“MainFrame”)
rebirthMenu = 主要框架:WaitForChild(“RebirthMenu”)
主要按钮= 脚本.Parent:WaitForChild(“MainButton”)
重生按钮= rebirthMenu:WaitForChild(“RebirthButton”)
strengthToRebirth = rebirtMenu:WaitForChild(“StrengthToRebirth”)
rebirths = player:WaitForChild(“leadestats”)。重生 < - 我认为这是
问题的比特。

strengthToRebirth.Text =“您至少需要” .. math.floor((starterRebirthAmount +(rebirths.Value)*数学.sqrt500000 )))..“力量才能重生”

主按钮.MouseButton1Click:Connect(function()

mainFrame.Visible =不是 mainFrame.Visible 

endrebirthButton.MouseButton1ClickConnectfunction()
result = replicatedStorage.Remotes.RebirthInvokeServer()
如果结果==真则
重生按钮文本=“成功重生”
等待(1)
重生按钮文本=“点击此处重生“
否则如果结果==“NotEnoughStrength”则
重生按钮文本=“不够强壮!”
等待(1)
重生按钮文本=“单击此处进行重生”

endrebirthsGetPropertyChangedSignal(“Value”):Connectfunction()

strengthToRebirth.Text =“您至少需要” .. math.floor((starterRebirthAmount +(rebirths.Value)*数学.sqrt(5000000 )))..“力量才能重生”)

我每次都收到相同的错误。 21:10:20.963 -

在 'Players.Archerofcool:WaitForChild(“Leadestats”)'上可能会产生无限产量

点赞
用户2858170
用户2858170

请在使用任何函数之前阅读文档!

来自 https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild

WaitForChild

如果调用此函数超过5秒钟而没有返回,并且没有指定timeOut参数,则将在输出中打印警告,表示线程可能无限制地yield;该警告采用"X:WaitForChild("Y")"的形式,其中X是父级名称,Y是子对象名称。

2019-11-13 06:51:16
用户2860267
用户2860267

WaitForChild()函数很适合在等待世界中的物品加载时使用,比如等待玩家及其外观。但正如Piglet指出的那样,不提供超时时间将导致它抛出像你看到的错误。

当你提供了超时时间,函数将返回nil,并且你需要能够对这种情况做出反应。

如果你确定脚本执行时所有物品都已加载完成,就可以像获取普通索引一样直接获取它们。

--等待物品加载完成……
while script.Parent:WaitForChild("MainFrame", 1) == nil do
    wait(1)
end

--获取所有元素
local mainButton = script.Parent.MainButton
local mainFrame = script.Parent.MainFrame
local rebirthMenu = mainFrame.RebirthMenu
local rebirthButton =  rebirthMenu.RebirthButton
local strengthToRebirth = rebirthMenu.StrengthToRebirth

--等待玩家加载完成
local player = game.Players.LocalPlayer
while player:WaitForChild("leaderstats", 1) == nil do
    wait(1)
end
local rebirths = player.leaderstats.Rebirths
2019-11-14 17:40:17