Scripting Errors With Next Page GUI Button

Hello! I was trying to make a Horror Stories GUI game and I got most of the game working, but my super sized Next Page button seems to not work, can someone please help me figure out why? Here is the code:

local bin = script.Parent.Parent

local gui = script.Parent.Parent.Parent.MainMenu

local Text1 = script.Parent.Parent.Text1

local Text2 = script.Parent.Parent.Text2

local Text3 = script.Parent.Parent.Text3

local Text4 = script.Parent.Parent.Text4

local Text5 = script.Parent.Parent.Text5

local Text6 = script.Parent.Parent.Text6

local Text7 = script.Parent.Parent.Text7

local Text8 = script.Parent.Parent.Text8

local Text9 = script.Parent.Parent.Text9

local Text10 = script.Parent.Parent.Text10

local Image1 = script.Parent.Parent.Image1

local Image2 = script.Parent.Parent.Image2

local Image3 = script.Parent.Parent.Image3

local Page1 = script.Parent.Parent.Page1

local Page2 = script.Parent.Parent.Page2

local Page3 = script.Parent.Parent.Page3

local Page4 = script.Parent.Parent.Page4

local Page5 = script.Parent.Parent.Page5

local Page6 = script.Parent.Parent.Page6

local Page7 = script.Parent.Parent.Page7

local Page8 = script.Parent.Parent.Page8

local Page9 = script.Parent.Parent.Page9

local Page10 = script.Parent.Parent.Page10

local Button = script.Parent

function leftClick()

if Page1 == true then

Text1.Visisble = false

Text2.Visible = true

Page1 = false

Page2 = true

print("Next Page has been completed!")

elseif Page2 == true then

Text2.Visisble = false

Text3.Visible = true

Page2 = false

Page3 = true

print("Next Page has been completed!")

elseif Page3 == true then

Text3.Visisble = false

Text4.Visible = true

Page3 = false

Page4 = true

print("Next Page has been completed!")

elseif Page4 == true then

Text4.Visisble = false

Text5.Visible = true

Page4 = false

Page5 = true

Image1.Visible = false

Image2.Visible = true

print("Next Page has been completed!")

elseif Page5 == true then

Text5.Visisble = false

Text6.Visible = true

Page5 = false

Page6 = true

print("Next Page has been completed!")

elseif Page6 == true then

Text6.Visisble = false

Text7.Visible = true

Page6 = false

Page7 = true

print("Next Page has been completed!")

elseif Page7 == true then

Text7.Visisble = false

Text8.Visible = true

Page7 = false

Page8 = true

print("Next Page has been completed!")

elseif Page8 == true then

Text8.Visisble = false

Text9.Visible = true

Page8 = false

Page9 = true

Image2.Visible = false

Image3.Visible = true

print("Next Page has been completed!")

elseif Page9 == true then

Text9.Visisble = false

Text10.Visible = true

Page9 = false

Page10 = true

print("Next Page has been completed!")

Button.Text = ("Complete Story")

elseif Page10 == true then

gui.Visible = true

gui.SlenderDone.Visible = true

wait(0.1)

bin.Visible = false

print("Button scripts ended successfully!")

end

end

script.Parent.MouseButton1Click:Connect(leftClick)

Did you really mean for the script to check for Page1’s (and others) existence?
if Page1 == true then
This part checks if Page1 exists, which is a nonsense because the script would error before. Or I might be wrong because in last few weeks my brain is weak.

EDIT: This does not seem to be the case, but your script attempts to treat an object value (Page1) as a boolean.

1 Like

Never mind I managed to fix it by re-coding it to do a bunch of waits instead of elseifs…

2 Likes

Can you clarify what you mean when you say it “seems to not work”? Is there a specific error message? Do the printouts show up? Does nothing happen?

A few things to try:

  • Are you connecting the MouseButton1Down event from the button to call the leftClick() function? This is what I think the problem most likely is.
button.MouseButton1Down:Connect(leftClick)
  • Add indents into your code so that it can be read more easily, the source of your problem could easily be a missing “end”, (if an error is coming up saying that there is a missing one, of course)
  • You wrote:
Page1 = false --applies to the other pages too
Page2 = true

This overwrites the Page1 and Page2 variables to contain false instead of the object. Instead, you should write:

Page1.Visible = false
Page2.Visible = true
  • Also, if you are doing this with a large volume of pages, it may benefit you from storing them in an array, and using a function to switch back and forth between pages in the array.

This is definitely NOT the solution. A solution to a problem is fixing the existing code, not making a different new one. And also… oh, @PixEclipz just said that.

1 Like