How can I detect the current page of a UIPageLayout

Hello, so I really would like to know how I can get the current page of a ui page layout. I tried using .CurrentPage but that returns an instance. Not number. Can someone please help me? This is my script:

local Button = script.Parent
local UiPageLayout = Button.Parent.InventoryFrame.UIPageLayout
local function GetCurrentAmountOfPages()
	local Amount = 0
	for i,v in pairs(UiPageLayout.Parent:GetChildren()) do
		if v:IsA("Frame") then
			Amount +=1
		end
	end
	return Amount
end

UiPageLayout.Changed:Connect(function()
	print(UiPageLayout. GetCurrentAmountOfPages())
	if UiPageLayout.CurrentPage == GetCurrentAmountOfPages() then
		script.Parent.Visible = false
	else
		script.Parent.Visible = true
	end
end)
Button.MouseButton1Click:Connect(function()
	UiPageLayout:Next()
end)

I think if each page was named with a unique name you could just use that in a search through a list of pages and get the number from that.

3 Likes