Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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().

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

This discussion is preserved as it was. New answers, comments, and votes are closed.