I'm making a page system but I have these scripts inside every single button but with only the numbers changed.
My pages go 1-9
I'm wondering if there is a far better way of doing this, because when I wind up with an error I have to fix around 17 scripts all together..
If there is a better way to do this, I will just have it in one local script that does everything and have only two buttons (back and next) in the frame that holds everything.
Next Buttons
local Content = script.Parent.Parent.Parent local PageFour = script.Parent.Parent --Current local PageFour = Content.PageFour --Next local Next = script.Parent Next.MouseButton1Down:connect(function() PageThree.Visible = false --Current PageFour.Visible = true --Next end)
Back Buttons
local Content = script.Parent.Parent.Parent local PageThree = script.Parent.Parent --Current local PageTwo = Content.PageOne --Previous local Back = script.Parent Back.MouseButton1Down:connect(function() PageThree.Visible = false --Current PageTwo.Visible = true --Previous end)
Simple! Just remove all that scripting and put a DoubleConstrainedValue into your GUI and I will define it as dcv for D-oubleC-onstrainedV-alue. Then do this:
function changeslide(num) for i,v in pairs(script.Parent:GetChildren()) do if v:IsA("Frame") then if v.Name:Sub(5,5) == num then v.Visible = true elseif v.Name:Sub(5,5) ~= num then v.Visible = false end end end script.Parent.Next.MouseButton1Click:conncet(function(n) dcv.Value = dcv.Value+1 if dcv.Value > dcv.MaxValue then dcv.Value = dcv.MinValue changeslide(dcv.Value) end) script.Parent.Back.MouseButton1Click:conncet(function(n) dcv.Value = dcv.Value-1 if dcv.Value < dcv.MinValue then dcv.Value = dcv.MaxValue changeslide(dcv.Value) end)
Notice I defined Next and Back as the two buttons being pressed for the Left or Right Page. Just make sure to change the DoubleConstrainedValue Max and Min values: Max = how many you have total, Min = 1.
Make sure that each page is called page# the # signifies your number value. So say page 6, I would name it page6. Make sure that they are also frames.