I'm trying to use GetChildren to take several frames and tell them all to slowly fade out and set their visibility to false, and I'm doing this with ImageTransparency. However, when I try to do this with the script, it gives me an error code. How would I fix this?
Script:
P = script.Parent
P.MouseEnter:connect(function()
P.Size = P.Size + UDim2.new(0.06, 0, 0.03, 0)
P.Position = P.Position - UDim2.new(0.03, 0, 0.015, 0)
end)
P.MouseLeave:connect(function()
P.Size = P.Size - UDim2.new(0.06, 0, 0.03, 0)
P.Position = P.Position + UDim2.new(0.03, 0, 0.015, 0)
end)
P.MouseButton1Click:connect(function()
local B = P.Parent:GetChildren()
for i=1, 20 do
wait(0.04)
B.ImageTransparency = B.ImageTransparency + 0.05
end
B.Visible = false
end)
Error Code: 15:05:39.262 - Players.EnderGamer358.PlayerGui.MenuGui.Base2.PlayButton.ButtonHandler:17: attempt to perform arithmetic on field 'ImageTransparency' (a nil value) 15:05:39.264 - Stack Begin 15:05:39.265 - Script 'Players.EnderGamer358.PlayerGui.MenuGui.Base2.PlayButton.ButtonHandler', Line 17 15:05:39.265 - Stack End

13 comments
you actually index with integers in a array, not "meaningless numbers"
They are not called "in pairs" loop. That is the wrong terminology. You are looking for the term "for".
for loops include
for i=1,7 do,for i,v in ipairs(x) doandfor i,v in pairs(x) do"The other answer's solution will not work. The indexes in a :GetChildren() call are meaningless numbers, not the name of the object. This is (probably) because multiple children of an instance can have the same name." This is wrong. All arrays have indices, those are indices. Each item has its own index
But they aren't called "in pairs" loops. They're for loops. Keyword for.
yes, each item has its own index, and the point is that this isn't based on the name of the instance like the other person thought. meaningless as in unrelated to what the instance actually is
alright, i'll edit my answer to be clear about the for loop
That doesn't make any sense. Meaningless is the wrong term.
Okay, this script didn't work out either. I had to switch a couple things around to fit my needs for the script, but all in all, it's changing the background transparency of the buttons, not the image transparency like I was hoping. If you could help fix this I'd greatly appreciate it.
^ Line 6 should say ImageTransparency instead of transparency, my bad. To incapaz, I guess I was unclear. I'll edit the answer to be clear about what I meant (unrelated to the value, not completely random)
That still didn't do the trick. I'll fiddle around with the code a bit to see if that solves anything.
works for me, not sure what your issue is. did you fix line 2 where I put kept P instead of parent? (fixed in updated script)
Ah, nevermind, it's working now. I had it set to search for ImageLabels instead of ImageButtons at Line 10. Thanks for your help!