Need some help with math!

hello everyone!
I need some help with something i’m making…
I need to automatically define button .NextSelectionDown using math.

Let me explain.

Let’s suppose we have a list!
Example;
image
What I need to do is this;
If I press key DOWN
This happens;
image

So, I already got system done, but I have to define the NextSelectionDown

So, what I need to do is this;
I have defined a number which will return the current number from 1,4 on the X list
Like this
image (In every view button created)
So what I need to know is
image
What do I use to automatically detect what’s under me automatically
So if i’m at 1, 5 is down me.

What operator would I use or how can I do this?

if you didn’t understand;

If we have 4 slots in a UI grid layout
[1] 4 Slots,
[2] 4 Slots,
[3] 4 Slots,

And we’re at the [2] in the slot number 1
If we do complete here then we will know that the slot down is the list [3] number 1.

Couldn’t you just do +4? _ ___

1 Like

It works sometimes but sometimes no


I mean weird it should work tho im a dummy
Here’s code if you want to check;

local Count = 0
		for ignore,TEMPLATE in pairs(TextureShop.ScrollingFrame:GetChildren()) do
			if (TEMPLATE:isA("ImageLabel")) then
				Count += 1
				if (AllTemplates[Count + 1]) then
					TEMPLATE.view.NextSelectionRight =  AllTemplates[Count + 1].view
				end
				if (AllTemplates[Count - 1]) then
					TEMPLATE.view.NextSelectionLeft = Count ~= 1 and AllTemplates[Count - 1].view or TextureShop.Buttons['4next']
				end
				if (AllTemplates[Count + 4]) then
					TEMPLATE.view.NextSelectionDown = AllTemplates[Count + 4].view
				end;
			end
		end

I’m using Count exchange of ignore because there’s a few UI tools (grid layout,list layout)

I think you should name each layer and in that way the number would be assigned according to how you decide it for sure very good work is being excellent

It works fine, its the 2nd for some reason… f

Could you name all of the frames a number 1-16 or put an int value numbered 1-16 inside each frame. Then use UserInputService and if the input is Enum.KeyCode.Up then look for and select a frame that is 4 higher than the current frame, if the input is Enum.KeyCode.Right then look for and select a frame that is 1 higher etc.