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

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)

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:

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.

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