How to create a page changing system

Check that they are with

if not v:IsA("GuiButton") then
    continue
end

at the beginning of your loop.

Also, use MouseButton1Click, not Button1Down (the latter is not valid, see my provided example for the way I would code this).

now I get a 20:35:14.925 MouseButton1Click is not a valid member of Frame "Players.DDZ_76.PlayerGui.tester.PageButtons.TopBar" - Client - LocalScript:3 error whenever I run the script

You’ve added my if check to the beginning of the for loop? It should make the loop skip the current item if it isn’t a button (Text or Image)

Oh I but the if inside the loop.

Edit:
Is this how it should be? it still errors out

if not v:IsA("GuiButton") then
	for i, v in pairs(script.Parent.PageButtons:GetChildren()) do
		v.MouseButton1Click:Connect(function()
			print(v)
		end)
	end
end
for i, v in ipairs(script.Parent.PageButtons:GetChildren()) do
    if not v:IsA("GuiButton") then
        continue
    end
    v.MouseButton1Click:Connect()
end
1 Like

Ah I see what I did wrong before, that’s how I had it, just put v.MouseButton1Click:Connect() in the wrong spot, thank you.

So this is what I am using now, but this errors out. The names of the buttons and the pages are the same by the way

for i, v in pairs(script.Parent.PageButtons:GetChildren()) do
	if not v:IsA("GuiButton") then
		continue
	end
	v.MouseButton1Click:Connect(function()
		script.Parent.PageFrame.UIPageLayout:JumpTo(script.Parent.PageFrame:FindFirstChild(v.Name))
	end)
end

I get both this error:
20:55:27.092 Players.DDZ_76.PlayerGui.tester.LocalScript:24: Expected '(', '{' or <string> when parsing function call, got ')' - Studio - LocalScript:24

And this error:
20:55:29.599 Object passed to UIPageLayout JumpTo is not a GuiObject - Client - LocalScript:6

(For any jumping to this as the solution, read the entire thread, as there is a lot more information in its history.)

I don’t see an obvious issue. Maybe giving some of these longer expressions variable names will help you find the bug?

Additionally, try printing things like v.Name and the FindFirstChild to see what they’re returning.

Alright, I discovered the issue, accidentally added another number into the name of a text object.

1 Like