我该如何解决 Infinite yield possibility?

How do i fix Infinite yield possibility?

以下代码位于 Drive Seat 内的脚本中,当玩家坐在座位上时,它会给出以下输出

“'Workspace 上的产量可能是无限的。Car4.DriveSeat:WaitForChild("Humanoid")"

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

function onSeated(isSeated,Seat)
    if humanoid ~= nil then
    local p = game.Players:FindFirstChild(n.Name)
        if p.Team.Name == "Thieves" then
            game.StarterGui.ThiefWinScreen.Frame.TextLabel.Script.Disabled = false
        end
    end
end
humanoid.Seated:Connect(onSeated(isSeated, Seat))

您参考 Roblox manual 并找到:

Instance:WaitForChild(childName, timeOUt)

Returns the child of the Instance with the given name. If the child does not exist, it will yield the current thread until it does. If the timeOut parameter is specified, this function will return nil and time out after timeOut seconds elapsing without the child being found.

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.

因此,为避免此警告,请为 timeOut 提供一个值,或确保在 5 秒内找到 child。