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

Why didn't this Tweening script work?, what is "Infinite yield"?

Asked by 7 years ago

I'm trying to make a tween GUI, I make a script for it and it didn't work. The output said this "Infinite yield possible on 'Players.Player1.PlayerGui.ButtonGUI:WaitForChild("ButtonGUI")". I'm a beginner to scripting and I don't know anything about it. Here's the script:

local TextButton = script.Parent.Parent.Parent.ButtonGUI:WaitForChild ('ButtonGUI').TextButton
local toggle = false
script.Parent.MouseButton1Click:connect(function()
    if toggle == false then
TextButton:TweenPosition(UDim2.new(0,10,0,160),"Out", "Sine",1)
             toggle = true
        else
TextButton:TweenPosition(UDim2.new(0,10,0,1000),"in", "Sine",1)

    end
end)
0
It mean's that it cannot find "Players.Player1.PlayerGui.ButtonGUI:WaitForChild("ButtonGUI")" crywink 419 — 7y

1 answer

Log in to vote
2
Answered by
duckwit 1404 Moderation Voter
7 years ago

The Short Answer

You probably want to change line 1 from:

local TextButton = script.Parent.Parent.Parent.ButtonGUI:WaitForChild ('ButtonGUI').TextButton

To:

local TextButton = script.Parent.Parent.Parent:WaitForChild ('ButtonGUI').TextButton

Spot the difference? You were calling WaitForChild('ButtonGUI') on ButtonGUI itself! But ButtonGui can't be a child of ButtonGUI unless you named a child of ButtonGUI with the name of its parent (which isn't good for clarity).

The Long Answer

'Yield' is a term that arises in multi-threaded programming. Yikes! Who asked for that, eh?

Each script in ROBLOX can be thought of as a different thread - a unique, isolated unit of computation that, at some point, gets exclusive access to the CPU. All of the threads in a game take turns running on the CPU, and sometimes a thread skips its turn because it is waiting for something to happen before it can continue.

A whole ROBLOX game has lots and lots of these mini programs, threads, running all the time. There are threads for networking (sending information between clients and the server), for physics simulation, for displaying graphics to the player, and for running all of the user scripts in a place.

There are some special functions in RBXLua which allow a thread to say "skip my turn while I wait for this". One that you may have come across is wait(), which blocks the script that it was called in from running for some time interval. wait() is like the thread is saying "skip me until some has elapsed, I don't want to keep running yet" - this is a kind of yielding, when a thread says "skip me for now" it is yielding its right to run on the CPU.

So what is an infinite yield warning? That means that a thread is waiting for something to happen, but it doesn't seem like it ever will happen! Imagine a script using workspace:WaitForChild("Blah") - if 'Blah' doesn't exist, and nothing is going to create it, then that script will be waiting for something which will never exist. It'll be waiting forever. That's an infinite yield.

Whenever you call WaitForChild(), you better be sure that you're waiting for something which really does, or shortly will, exist, or you'll get stuck waiting forever!

The error that you found is a classic example of incorrectly traversing the instance hierarchy, that is, looking for something in the wrong place. Make sure the path to ButtonGui is correct and you won't get stuck in an infinite yield waiting for it.

0
Thanks! MArzalAlBuchariZ 33 — 7y
Ad

Answer this question