UIPageLayout:Next() not working in any script, works in command bar

Genuinely unsure why this isn’t working but trying to use UIPageLayout:Next() does not do anything in both a localscript or a server script.

The localscript is:

repeat
   wait(3)
   script.SurfaceGui.UIPageLayout:Next()
until nil

The server script is:

repeat
	wait(3)
	game.Workspace.scrollingbillboard.SurfaceGui.UIPageLayout:Next()
until nil

The scripts were inside the part where the SurfaceGui is located, and I moved the server script into ServerScriptService, and it still refuses to work. Changing the localscript to the server script’s code doesn’t help. There’s nothing inside Output to show if the code is incorrect

However, running the server script in Studio’s Play mode is perfectly fine, so I genuinely have no clue what I’m doing wrong at this point.

1 Like

If you want to see the effect of advancing to the next page, you will need to include some logic to update the page displayed in the page layout based on the current page index. Here is a fixed script of yours on how you could do this using a UIPageLayout with a Frame as its parent and a series of ImageLabel objects as its pages

local pageLayout = script.SurfaceGui.UIPageLayout
local pages = script.SurfaceGui.Pages:GetChildren()

repeat
	wait(3)
	pageLayout:Next()
	local currentPageIndex = pageLayout.CurrentPage
	local currentPage = pages[currentPageIndex]
	currentPage.Visible = true
	for _, page in pairs(pages) do
		if page ~= currentPage then
			page.Visible = false
		end
	end
until nil
1 Like

Why would I have to do all of this? I’ve had UIPageLayout work before without needing to set visibility for any other ‘page’. For example:


This works perfectly fine in another experience I have on the backburner. It’s inside a localscript in StarterGui, so what’s the difference between this gui and SurfaceGuis when it comes to UIPageLayout?

I’ll reiterate: My code only works when I insert it into the command bar in Play mode. Otherwise, no matter what position or what script is used, UiPageLayout:Next() refuses to work. I shouldn’t need a 10-page dissertation when it’s worked perfectly fine in other instances.

1 Like