GUI "CurrentPage" property not updating server-side

  1. What do you want to achieve?
    When the player switches pages on a UIPageLayout, I want this code to run in a server script:
local content = plr.PlayerGui.Menus.Operator.Function.Operators.Content.UIPageLayout.CurrentPage

content.Changed:Connect(function()
	prepareOperatorGui()
end)
local function prepareOperatorGui()
	-- Variables --
	local operatorList = infoManager:GetOperatorList(content.Name)
	local operators = game:GetService("ServerStorage").Operators[content.Name]

	for _,item in ipairs(operatorList) do
		if operators[item]:FindFirstChild("Humanoid") then
			if content:FindFirstChild(item) ~= nil then continue end

			-- Create ViewportFrame
			local viewPortFrame = content.ViewportFrame:Clone()
			viewPortFrame.Name = item
			viewPortFrame.Parent = content

			-- Create operator preview
			local Preview = operators[item]:Clone()
			Preview.Parent = viewPortFrame

			local Camera = Instance.new("Camera")
			Camera.Parent = viewPortFrame
			Camera.CFrame = Preview.Head.CFrame + Preview.Head.CFrame.LookVector * 5
			Camera.CFrame = CFrame.new(Camera.CFrame.Position,Preview.Head.Position)

			viewPortFrame.CurrentCamera = Camera

			-- Set spawn button
			viewPortFrame.SpawnButton.Name = item

			-- Set view button
			viewPortFrame.ViewButton.Name = item

			viewPortFrame.Visible = true

			print(script.Name.. ": Operator ".. item.. " preview created")
		end
	end
end

Pages are managed by this local script:

local title = script.Parent.Parent.Title
local pageLayout = script.Parent.UIPageLayout
local nextButton = title.NextPage
local prevButton = title.PreviousPage

nextButton.MouseButton1Click:Connect(function()
	pageLayout:Next()
	title.Title.Text = pageLayout.CurrentPage.Name
end)

prevButton.MouseButton1Click:Connect(function()
	pageLayout:Previous()
	title.Title.Text = pageLayout.CurrentPage.Name
end)

pageLayout:JumpToIndex(0)
  1. What is the issue?
    The issue is that the “CurrentPage” only updates on the client side, so the server never sees the change and therefore never fires.

  2. What solutions have you tried so far?
    I’ve tried using remoteEvents, but the “CurrentPage” property is read-only, so I can’t update it on the server so the code will run correctly. I cannot find anything that helped on the Dev Forum or on Youtube.

That’s because it doesn’t replicate to the server. All gui actions done from the client don’t replicate to the server.

Example:
Client opens settings menu, Server will not see that the settings menu is not opened.

All gui scripting should be handled by the client via local scripts or modules. Anything that the server needs should be sent through a remote event, and if it’s abusable data, for example for hit registrations, you make checks on the server.

But for your case from my understanding of your code, your just trying to update the page with the operators, which should be done on the client. You’d need to move your operators to ReplicatedStorage so the client can access them and do it all on the client. This will also put less stress on the server aswell.

So this would all go inside your local script, but instead of ServerStorage it’d be ReplicatedStorage

local function prepareOperatorGui()
	-- Variables --
	local operatorList = infoManager:GetOperatorList(content.Name)
	local operators = game:GetService("ServerStorage").Operators[content.Name]

	for _,item in ipairs(operatorList) do
		if operators[item]:FindFirstChild("Humanoid") then
			if content:FindFirstChild(item) ~= nil then continue end

			-- Create ViewportFrame
			local viewPortFrame = content.ViewportFrame:Clone()
			viewPortFrame.Name = item
			viewPortFrame.Parent = content

			-- Create operator preview
			local Preview = operators[item]:Clone()
			Preview.Parent = viewPortFrame

			local Camera = Instance.new("Camera")
			Camera.Parent = viewPortFrame
			Camera.CFrame = Preview.Head.CFrame + Preview.Head.CFrame.LookVector * 5
			Camera.CFrame = CFrame.new(Camera.CFrame.Position,Preview.Head.Position)

			viewPortFrame.CurrentCamera = Camera

			-- Set spawn button
			viewPortFrame.SpawnButton.Name = item

			-- Set view button
			viewPortFrame.ViewButton.Name = item

			viewPortFrame.Visible = true

			print(script.Name.. ": Operator ".. item.. " preview created")
		end
	end
end

And yes, CurrentPage is read-only, but there is methods to change the pages via local script such as:

UIPageLayout:JumpTo(page) 		    -- page would be the frame instance
UIPageLayout:JumpToIndex(index)     -- index would be a number (based on LayoutOrder)
UIPageLayout:Next() 				-- Jumps to the next index (based on LayoutOrder)
UIPageLayout:Previous() 			-- Jumps to the previous index (based on LayoutOrder)
1 Like

Thankyou.
Not every operator can be used by everyone (gamepasses/badges/levels, etc.) which is why I am hesitant to put it in ReplicatedStorage. But if that’s the only way I can, I’ll find a way to make it secure.