如何修复 Roblox 无限产量错误? [英] How do I fix Roblox Infinite Yield Error?

查看:92
本文介绍了如何修复 Roblox 无限产量错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<---This is my current local script--->

local replicatedStorage = game:GetService("ReplicatedStorage")
local starterRebirthAmount = 5000

local player = game.Players.LocalPlayer
local mainFrame = script.Parent:WaitForChild("MainFrame")
local rebirthMenu = mainFrame:WaitForChild("RebirthMenu")
local mainButton = script.Parent:WaitForChild("MainButton")
local rebirthButton = rebirthMenu:WaitForChild("RebirthButton")
local strengthToRebirth = rebirthMenu:WaitForChild("StrengthToRebirth")
local rebirths = player:WaitForChild("leaderstats").Rebirths <--The Bit I think is causing the 
problems.

strengthToRebirth.Text = "You need at least "..math.floor((starterRebirthAmount + (rebirths.Value) * 
math.sqrt(500000))).." strength to rebirth"

mainButton.MouseButton1Click:Connect(function()

mainFrame.Visible =  not mainFrame.Visible

end)

rebirthButton.MouseButton1Click:Connect(function()
local result = replicatedStorage.Remotes.Rebirth:InvokeServer()
if result == true then
rebirthButton.Text  = "Successfully Rebirthed"
wait(1)
rebirthButton.Text = "CLICK HERE TO REBIRTH"
elseif result == "NotEnoughStrength" then 
rebirthButton.Text = "Not Strong Enough!"
wait(1)
rebirthButton.Text = "CLICK HERE TO REBIRTH"

end
end)

rebirths:GetPropertyChangedSignal("Value"):Connect(function()

strengthToRebirth.Text = "You need at least "..math.floor((starterRebirthAmount + (rebirths.Value) * 
math.sqrt(5000000))).." strength to rebirth" end)

我每次都遇到同样的错误.21:10:20.963 -

I get the same error every time. 21:10:20.963 -

无限产量可能在'Players.Archerofcool:WaitForChild("leaderstats")'

Infinite yield possible on 'Players.Archerofcool:WaitForChild("leaderstats")'

推荐答案

WaitForChild() 如果您必须等待事物加载到世界中,例如玩家及其外观,则非常适合.但正如 Piglet 指出的那样,不提供超时会导致它抛出您所看到的错误.

WaitForChild() is good if you have to wait for things to load into the world, like a player and their appearance. But as Piglet pointed out, not providing a timeout will cause it to throw errors like the one you're seeing.

当您提供超时时,该函数将返回 nil,您需要能够对这种情况做出反应.

When you provide a timeout, the function will return nil, and you need to be able to react to that case.

如果您确定在脚本执行时所有内容都已加载,您可以像获取普通索引一样简单地获取所有内容.

If you are sure that everything had loaded in by the time your script executes, you can simply grab everything like you would a normal index.

-- wait for the stuff to load...
while script.Parent:WaitForChild("MainFrame", 1) == nil do
    wait(1)
end

-- grab all the elements
local mainButton = script.Parent.MainButton
local mainFrame = script.Parent.MainFrame
local rebirthMenu = mainFrame.RebirthMenu
local rebirthButton =  rebirthMenu.RebirthButton
local strengthToRebirth = rebirthMenu.StrengthToRebirth

-- wait for the player to load in
local player = game.Players.LocalPlayer
while player:WaitForChild("leaderstats", 1) == nil do
    wait(1)
end
local rebirths = player.leaderstats.Rebirths

这篇关于如何修复 Roblox 无限产量错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆