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

Whats the best way to loop looking for a Instance/Object?

Asked by 3 years ago

Im tryna have the script wait until it finds the value and makes sure it isn't {}. Should I just use WaitForChild and have the max wait time like 30? Whats the best method?

repeat wait(1) until RS:FindFirstChild('PanelStuff').GameInfo.ServerItemsInfo.Value ~= {}

2 answers

Log in to vote
1
Answered by
Speedmask 661 Moderation Voter
3 years ago
Edited 3 years ago

what you have is probably ok if you’re just looking for one thing every one second, but the most optimal way to do these kinds of things is with a signal. a signal meaning, using Connect(). with connections you can forget about constant checks, the connect will do it for you without loops, which can save a lot of lag.

it looks like you’re using an Instance. luckily, roblox has a handy-dandy Instance.ChildAdded event. you can tap into that. if you’re only doing it once, you could even use Instance.ChildAdded:Wait().

Ad
Log in to vote
0
Answered by 3 years ago

the best method for me is using for instead of repeat:

for i, v in pairs(RS:GetDescendants) do 
    if v.Name[i] = "PanelStuff" then
        v.GameInfo.ServerItemsInfo.Value ~= {}
    end
end

Answer this question