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
01 | local Content = script.Parent.Parent.Parent |
02 | local PageFour = script.Parent.Parent --Current |
03 | local PageFour = Content.PageFour --Next |
04 | local Next = script.Parent |
05 |
06 |
07 | Next.MouseButton 1 Down:connect( function () |
08 | PageThree.Visible = false --Current |
09 | PageFour.Visible = true --Next |
10 | end ) |
Back Buttons
01 | local Content = script.Parent.Parent.Parent |
02 | local PageThree = script.Parent.Parent --Current |
03 | local PageTwo = Content.PageOne --Previous |
04 | local Back = script.Parent |
05 |
06 |
07 | Back.MouseButton 1 Down:connect( function () |
08 | PageThree.Visible = false --Current |
09 | PageTwo.Visible = true --Previous |
10 | 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:
01 | function changeslide(num) |
02 | for i,v in pairs (script.Parent:GetChildren()) do if v:IsA( "Frame" ) then |
03 | if v.Name:Sub( 5 , 5 ) = = num then |
04 | v.Visible = true |
05 | elseif v.Name:Sub( 5 , 5 ) ~ = num then |
06 | v.Visible = false |
07 | end |
08 | end |
09 | end |
10 |
11 | script.Parent.Next.MouseButton 1 Click:conncet( function (n) |
12 | dcv.Value = dcv.Value+ 1 |
13 | if dcv.Value > dcv.MaxValue then |
14 | dcv.Value = dcv.MinValue |
15 | changeslide(dcv.Value) |
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.