I have an InstructionsGui that has 6 pages. there are 2 button named "Next Page" and "Previous Page" that switch between the pages of the GUI. Also, when the GUI is on The 6th page, the "Next Page" button text switches to say "Close". When the GUI is on the 6th page and you click on the "Close" button, I want the GUI to close, but it does not.
I would appreciate any ideas on how to get this local script to work. The local script is placed inside of my InstructionsGui ScreenGui.
--gui references
local InstructionsGui = script.Parent
local HelpGui = script.Parent.Parent.HelpGui
local Page_1 = script.Parent.Frame.Page_1
local Page_2 = script.Parent.Frame.Page_2
local Page_3 = script.Parent.Frame.Page_3
local Page_4 = script.Parent.Frame.Page_4
local Page_5 = script.Parent.Frame.Page_5
local Page_6 = script.Parent.Frame.Page_6
-- button references
local InstructionsButton = script.Parent.Parent.HelpGui.Frame.InstructionsButton
local nextPg = script.Parent.Frame.NextPage
local previousPg = script.Parent.Frame.PreviousPage
--variable to track page number
local PageNum = 0
--function to show instructions
local function showInstructions()
HelpGui:Destroy()
InstructionsGui.Enabled = true
InstructionsGui.Frame.Visible = true
Page_1.Visible = true
PageNum = 1
end
--function to show next page
local function nextPage()
PageNum = PageNum + 1
if PageNum == 7 then
PageNum = 6
end
if PageNum < 6 then
nextPg.Text = "Next Page"
else if PageNum == 6 then
nextPg.Text = "Close"
end
end
InstructionsGui.Frame:FindFirstChild("Page_"..PageNum).Visible = true
InstructionsGui.Frame:FindFirstChild("Page_"..PageNum - 1).Visible = false
end
--function to show previous page
local function previousPage()
PageNum = PageNum - 1
if PageNum == 0 then
PageNum = 1
end
if PageNum < 6 then
nextPg.Text = "Next Page"
else if PageNum == 6 then
nextPg.Text = "Close"
end
end
InstructionsGui.Frame:FindFirstChild("Page_"..PageNum).Visible = true
InstructionsGui.Frame:FindFirstChild("Page_"..PageNum + 1).Visible = false
end
--function to destroy gui after player is done reading instructions
local function closeInstructions()
InstructionsGui:Destroy()
InstructionsGui.Enabled = false
InstructionsGui.Frame.Visible = false
for i = 1, 6, 1
do
InstructionsGui.Frame:FindFirstChild("Page_"..PageNum):Destroy()
end
end
--event to show instructions
InstructionsButton.MouseButton1Click:Connect(showInstructions)
--event that flips to the next page, or destroys gui if player clicks close on the last page of instructions
if PageNum ~= 6 then
nextPg.MouseButton1Click:Connect(nextPage)
else if PageNum == 6 then
nextPg.MouseButton1Click:Connect(closeInstructions)
end
end
--event that flips the previous page
previousPg.MouseButton1Click:Connect(previousPage)
I think my problem resides in the function below, but I am not sure what to change to get the GUI to close.
--function to destroy gui after player is done reading instructions
local function closeInstructions()
InstructionsGui:Destroy()
InstructionsGui.Enabled = false
InstructionsGui.Frame.Visible = false
for i = 1, 6, 1
do
InstructionsGui.Frame:FindFirstChild("Page_"..PageNum):Destroy()
end
end

6 comments
Disabling the ScreenGui should be all there is to it. Try removing all of the lines from closeInstructions except for the line where you disable it.
okay, I'll try that and let you know if it works.
It's so strange, because i've been messing with the code and nothing seems to work, even your recommendation does not work, i am so lost.
ok, this might not be the best thing to do, but you should rewrite the code, so then you can have a better understanding of it, I think...
i've been rewriting the functions all day............
I have found the solution to my problem, i just made a function called pageRange() and then put nextPg.MouseButton1Click:Connect(closeInstructions) inside and if statement to detect when the GUI is on the last page