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?
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.
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
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