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?
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
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")