Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make this much more efficient?

Asked by 10 years ago

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

01local Content = script.Parent.Parent.Parent
02local PageFour = script.Parent.Parent --Current
03local PageFour = Content.PageFour  --Next
04local Next = script.Parent
05 
06 
07Next.MouseButton1Down:connect(function()
08PageThree.Visible = false --Current
09PageFour.Visible = true --Next
10end)

Back Buttons

01local Content = script.Parent.Parent.Parent
02local PageThree = script.Parent.Parent --Current
03local PageTwo = Content.PageOne --Previous
04local Back = script.Parent
05 
06 
07Back.MouseButton1Down:connect(function()
08PageThree.Visible = false --Current
09PageTwo.Visible = true  --Previous
10end)

2 answers

Log in to vote
1
Answered by 10 years ago

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:

01function changeslide(num)
02for i,v in pairs(script.Parent:GetChildren()) do if v:IsA("Frame") then
03if v.Name:Sub(5,5) == num then
04v.Visible = true
05elseif v.Name:Sub(5,5) ~= num then
06v.Visible = false
07end
08end
09end
10 
11script.Parent.Next.MouseButton1Click:conncet(function(n)
12dcv.Value = dcv.Value+1
13if dcv.Value > dcv.MaxValue then
14dcv.Value = dcv.MinValue
15changeslide(dcv.Value)
View all 22 lines...

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.

Ad
Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago

http://www.roblox.com/pages-item?id=165587731

Answer this question