Detecting every child in a folder

So I’m looking to add a feature where the GUI size increases and decreases depending on whether the mouse enters or leaves, example:

holderButtons.ChangelogFrame.MouseEnter:Connect(function()
	createTween(holderButtons.ChangelogFrame, "Size", holderButtons.ChangelogFrame.Size + UDim2.new(0,0,0.02,0), 0.05)
end)

holderButtons.ChangelogFrame.MouseLeave:Connect(function()
	createTween(holderButtons.ChangelogFrame, "Size", holderButtons.ChangelogFrame.Size - UDim2.new(0,0,0.02,0), 0.05)
end)

But, I have multiple frames inside of “holderButtons” and want to know if there is a more efficient way to do this, without using a for loop? Theyre all the same size so that shouldnt be an issue.

All help appreciated

1 Like
-- Connect to MouseEnter event of holderButtons
holderButtons.MouseEnter:Connect(function()
    adjustFrameSize(holderButtons, true) -- Increase size
end)

-- Connect to MouseLeave event of holderButtons
holderButtons.MouseLeave:Connect(function()
    adjustFrameSize(holderButtons, false) -- Decrease size
end)

-- Function to adjust size of child frames
function adjustFrameSize(parentFrame, increase)
    local increment = UDim2.new(0, 0, 0.02, 0)
    if not increase then
        increment = increment * -1
    end

    for _, childFrame in ipairs(parentFrame:GetChildren()) do
        if childFrame:IsA("Frame") then
            childFrame.Size = childFrame.Size + increment
        end
    end
end
1 Like

As the person above did, you should be able to connect the MouseEnter directly to the holderButtons frame, then scale it [holderButtons] accordingly, which should scale all child frames.

However, if that is what you want, please elaborate on why you don’t want a for loop?

1 Like

I was checking if there was a more efficient way of doing it.

1 Like

Reading over, so what I wanted it for each frame to scale. Ill attach a video.

1 Like
local p = game:GetService('Players').LocalPlayer.PlayerGui.ScreenGui
for _,button in p:GetChildren(), next do
	if typeof(button) ~= 'Frame' then
		-- do stuff here
	end
end

something like this, or u can do it directly in the loop

local p = game:GetService('Players').LocalPlayer.PlayerGui.ScreenGui
for _,button in p:GetChildren(), next do
	if typeof(button) ~= 'Frame' then
		assign(button)
	end
end

function assign(n)
	n.MouseEnter:Connect(function()
		createTween(holderButtons.ChangelogFrame, "Size", holderButtons.ChangelogFrame.Size + UDim2.new(0,0,0.02,0), 0.05)
	end)
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.