IsA is not working when looking for item

Hello, I have an issue with my code. The IsA is not working and im not sure why.

for i, v in pairs(Gui:WaitForChild("list"):GetDescendants()) do
	 if v:IsA("ImageButton") then
		
		v.MouseButton2Up:Connect(function()
                print("working")
         end)
      end
end

I have added WaitForChild to my variables in case they haven’t loaded but that hasn’t changed anything. What can i do to fix this issue?

1 Like

hey can you try putting print(v) and tell me if it prints all the things in the Gui.List since I might have an asnwer to this.

Can i see the full script. I wanna see the complete script

if i put a print(v) under for i, v in pairs(Gui:WaitForChild("list"):GetDescendants()) do it prints the items in the list but if put it in the if v:IsA("ImageButton") then then it doesn’t print anything.

why do you need to see the complete script? when the issue is this problem only

Actually,i might now the problem. You did not have image button. Or do you?

Send explorer

So are you sure you have imagebuttons in your Gui? Does it print the imagebutton names when you print the list>

I am sure that i have a image button
image

and when this button is pressed i want another gui to open

Alright, the ImagheButton name prints when you do print(v) right?

you can print out the object using print(tostring(v)) and if it’s nil then check if there is no warn for infinite yield:

for i, v in pairs(Gui:WaitForChild("list"):GetDescendants()) do
    print(tostring(v))
	 if v:IsA("ImageButton") then
		print(v.Name.." is an imagebutton")
		v.MouseButton2Up:Connect(function()
                print("working")
         end)
end

Edit: Forgot the mention, put a print after the IsA so you know if it worked

1 Like

no it doesn’t. It prints my the name of my UILayout that i have in the same Gui but not the name of the imagebbutton

Put print(v.ClassName) at the beginning of your for loop, it will allow you verify the type of various instances when doing GetDescendants()

It’s likely you dont have an ImageButton, as this script would work correctly

(also the code that you provided has a syntax error in it, missing an end at the end of the loop)

I think the end might be the problem

Yah, then you have to wait for all the gui to load a common way to do this would be putting it in ReplicatedStorage and then parenting it to the character otherwise if you want a simple dirty solution use polling.

based on my expereince the children gui don’t load sometimes after the parent gui loads. here’s how you wait for all the gui to load

local StarterGui = game:GetService("StarterGui")

repeat wait() 
until 
#StarterGui:GetDescendants() >= #game.Players.LocalPlayer.PlayerGui:GetDescendants()

Not really, because if he has like HDAdmin or any other item which adds a gui to the playerGui, it will yield, rather than checking if it’s equal to, check if it is greater than or equal to

Oh yah Oops it’s supposed to be a >=

i tried this, the imagebutton gets added into the folder that im searching for the image. This might be the problem

Also, what is “Gui” and can you show the whole Gui inside explorer

When the player presses clicks on an item it moves the item to list and then this loop should occur.
image

I think you are supposed to loop through the “clone” folder because all I see in the “list” folder is a UIGridLayout