Problems using GetDescendants()

I have a scrollingframe set up with multiple imagebuttons and in every imagebutton there is a textlabel called NewSelect. Every NewSelect’s text is 0 expect for one which is 1. How would I find the one where the text is 1 not 0?

Here is my current script:

for i, v in pairs(script.Parent.Parent.Parent.ScrollingFrame:GetDescendants()) do
	if v:IsA("NewSelect") then
		if v.Text == 1 then
			print("working") --just for example
		end
	end
end

The problem is that it doesn’t print out “working” and doesn’t show any errors.

1 Like

Instead of doing :IsA() do:

for i, v in pairs(script.Parent.Parent.Parent.ScrollingFrame:GetDescendants()) do
	if v.Name == "NewSelect" then
		if v.Text == 1 then
			print("working")
		end
	end
end
1 Like

IsA() is checking what the instance is, .Name is just seeing or changing the name

1 Like

Ah I understand now. But it still doesn’t print out “working”.

1 Like

Are you sure the text for NewSelect is set to 1? I don’t see why this wouldn’t be working otherwise

1 Like

On the line where you’re checking if v.Text == 1, change that to v.Text == ‘1’. That should fix your problem. :slight_smile:

3 Likes

Yeah that works now. Thank you very much!

1 Like

No worries :slight_smile: Glad I was able to help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.