Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Infinite yield possible - bug. How to fix?

Asked by
nanaluk01 247 Moderation Voter
8 years ago
Edited 8 years ago

It works in studio, but outside studio it does not work. The error is on line 20

I get this error in Server Log:

Infinite yield possible on 'Players.Nanaluk01.PlayerGuiWaitforChild("ChatGui")' Script 'ServerScriptService.Chat', Line 20

How can I fix this?

Here Is The Coding:

Please Note: -The Error Lies On Line 20 -The .Fr you can see is Frame. I don't know why it disappears in this question.

function UpdateOldLabels(Parent)
    for i,v in pairs(Parent:GetChildren()) do
        if v.Name:sub(1,4):lower() == "line" then
            local LineNumber = v.Name:sub(5)
            if LineNumber == "7" then
                v:Destroy()
            else
                v.Name = "line"..tostring(tonumber(LineNumber) + 1)
                v.Position = v.Position - UDim2.new(0,0,0,15)
            end
        end
    end
end

game.Players.PlayerAdded:connect(function(player)
    for _,v in ipairs(game:GetService("Players"):GetChildren()) do
        wait(1)
        UpdateOldLabels(v:WaitForChild("PlayerGui"):WaitForChild("ChatGui").Frame)
        if player then
            newchatline = Instance.new("TextLabel",v:WaitForChild("PlayerGui").ChatGui.Frame)
            newchatline.Text = "[Server] "..player.Name.. " Has Joined The Server!"
            newchatline.Size = UDim2.new(1,0,0,20)
            newchatline.Position = UDim2.new(0,0,1,-15)
            newchatline.Font = "ArialBold"
            newchatline.TextStrokeTransparency = 1
            newchatline.BackgroundTransparency = 1
            newchatline.BorderSizePixel = 0
            newchatline.FontSize = "Size18"
            newchatline.TextXAlignment = "Left"
            newchatline.TextYAlignment = "Top"
            newchatline.ClipsDescendants = true
            newchatline.Name = "line1"
            newchatline.TextColor3 = Color3.new(1,1,1)
        end
    end 
    UpdateOldLabels(game:GetService("StarterGui").ChatGui.Frame)
    newchatline:Clone().Parent = game:GetService("StarterGui").ChatGui.Frame
    player.Chatted:connect(function(msg)
        for _,v in ipairs(game:GetService("Players"):GetChildren()) do
            UpdateOldLabels(v:WaitForChild("PlayerGui").ChatGui.Frame)
            newchatline = Instance.new("TextLabel",v:WaitForChild("PlayerGui").ChatGui.Frame)
            newchatline.Text = player.Name..": "..msg
            newchatline.Size = UDim2.new(1,0,0,20)
            newchatline.Position = UDim2.new(0,0,1,-15)
            newchatline.Font = "ArialBold"
            newchatline.TextStrokeTransparency = 1
            newchatline.BackgroundTransparency = 1
            newchatline.BorderSizePixel = 0
            newchatline.FontSize = "Size18"
            newchatline.TextXAlignment = "Left"
            newchatline.TextYAlignment = "Top"
            newchatline.ClipsDescendants = true
            newchatline.Name = "line1"
            newchatline.TextColor3 = Color3.new(1,1,1)
        end
        UpdateOldLabels(game:GetService("StarterGui").ChatGui.Frame)
        newchatline:Clone().Parent = game:GetService("StarterGui").ChatGui.Frame
    end)
end)

2 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

That isn't an error, it's a warning.

Basically, WaitForChild will yield forever until the thing you're looking for is found. That is what 'infinite yield possible' means.

To 'fix' it, use the optional second argument of WaitForChild: the timeout (in seconds). If you want an infinite yield, which you don't, use math.huge. I suggest something around 20 seconds.

0
HI i do a cobatsystem but when i fixed some thnig my program crashed and when i got back is give this error ? crazygamespp -5 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

i get this weird error how do i gonna fix it hapend on a crash

19:32:18.826 - Infinite yield possible on 'Workspace.crazygamespp:WaitForChild("Right Arm")' 19:32:18.826 - Stack Begin 19:32:18.829 - Script 'ServerScriptService.CombatHandler', Line 16 19:32:18.829 - Stack End

picture here https://i.imgur.com/3G2zFq3.png

0
i liked job with that code 2 days and i know is was working until is crashed crazygamespp -5 — 4y

Answer this question