:IsA() not working

Oh boy here we go again… another devforum post… anyways for some odd reason :IsA() isn’t working for me. Everything in the for loop runs however in the :IsA() it does not.

local player = game.Players.LocalPlayer
local UI = player.PlayerGui:WaitForChild("UI")
local invGui = UI:WaitForChild("Inventory")

for i, itemButton in pairs(invGui.mFrame.ScrollingFrame.ItemList:GetDescendants()) do
	print("This works")
	if itemButton:IsA("ImageButton") then
		print("This doesnt work")
	end
end

As shown above “This works” will get printed but “This doesnt work” wont. Any Ideas?

1 Like

Firstly change the pairs to ipairs for better performance as it is suited to your case.

try changing it to this instead :

local player = game:GetService("Players").LocalPlayer
local UI = player.PlayerGui:WaitForChild("UI")

local invGui = UI:WaitForChild("Inventory")
local list = invGui:FindFirstChild("mFrame").ScrollingFrame.ItemList


for _, itemButton in ipairs(list :GetDescendants()) do

	if not itemButton:IsA("ImageButton") then return error("not an image button") end
		print("This DOES work")
	end

3 Likes

The issue is that there are other things in the list besides the image button so thats was why I was using IsA rather than if not itemButton:IsA("ImageButton")

The image buttons are within their frames in the List folder. In the frames are also text labels.

Send a picture of the UI model in workspace with descendants visible

Really the only reason it wouldn’t print is that itemButton simply is not ImageButton.

Here you go. Each item frame has the same structure.

path

It takes time for UI to come into existence, you’ll have to use :WaitForChild() instead of directly indexing mFrame, ScrollingFrame, and ItemList.

Edit: The ImageButtons also take time to replicate, somehow you’ll have to wait until they exist.

Yep that’s it. Had to add a wait before the for loop is done because of other things that happen with the inventory system.