So I have seen multiple games with similar style GUI’s that have a page-changing system, and they all seem to be pretty similar in terms of function, I was wondering how to create a similar effect, below is an example of what I am talking about:
I’ve created things similar, but my scripts are always inefficient and do not work the way they do in terms of the effect which depends on what side of the screen changes the direction of the tweeting frame. Sorry if my post is not clear, feel free to ask for clarification if necessary.
I made something like this once:
I created the menu frame, created pages and made the menu the pages’ parent.
Then I scripted a button:
local button = script.Parent
button.MouseButton1Click:Connect(function()
for i, children in pairs(button.Parent.Parent:GetChildren()) do
if children == button.Parent then
children.Visible = children.Visible
elseif children == button.Parent.Parent.Cash then
children.Visible = true
else
children.Visible = false
end
end
end)
I would personally change the position of the wanted page frame based on which position the frame is in relative to the current one. If you use a numerical index for the frames (1 = Home, 2 = Teams, etc.), then you could probably do:
local debounce = false -- are we tweening?
local currentFrame = 1
-- button pressing event, given newFrame
if debounce then
return
end
debounce = true
if newFrame < currentFrame then
newFrame.Position.X.Scale = -1
elseif newFrame > currentFrame then
newFrame.Position.X.Scale = 1
end
newFrame.Visible = true
-- animate newFrame in (position 0) and currentFrame out (position -newFrame.Position.X.Scale) with a tween, then wait for its completion
currentFrame.Visible = false
currentFrame = newFrame
debounce = false
-- end button pressing code
(some of the code in this example is left out as it’s a lot to type on my phone)
local function switchPage(currentFrame, newFrame)
-- code
end
for i, v in ipairs(header:GetChildren()) do
-- assuming all header children are buttons
v.MouseButton1Click:Connect(switchPage, i)
end
With luck that should work, but as previously mentioned I’m away for the day and can’t test myself.
Note: The button instances would also be named numbers so the loop iterates through them in the right order.
GetChildren returns an array of instances.
Pairs is slower since it parses the key name rather than saving an index (though the performance difference is negligible).
Probably be simpler eh? Granted still would need a way to create the effect that the GUI has when switching pages the direction of the frame coming in changes based on the current frame.
How that one probably works is assigning a value on how far in one direction it is, and then checking to see if the frame you’re currently on has a higher value than the frame you want to go to. That is my guess as to how it decides which direction the next frame comes from. From there it is just setting it to one side, and then tweening both frames in one direction or the other. (sorry if this doesn’t make much sense and there is probably a much simpler way to do this)
planning on still using something similar to this in my script, how would you modify it assuming that you had children that also were not TextButtons? I also tried this removing the non TextButton children and it still did not work.