Ad
Log in to vote
0

How does this function not activate when it should?

Asked by
Stravan 11
4 days ago
local nextbutton = script.Parent
local prevbutton = script.Parent.Parent.Backward
local view = 0

if view == 0 then
    nextbutton.MouseButton1Click:connect(function()
        view = 1
        print(view)
        print("page 2")
        script.Parent.Parent.BasicInfo.Visible = false
        script.Parent.Parent.Face.Visible = true
        script.Parent.Parent.Backward.Visible = true
    end)
    if view == 1 then
        script.Parent.Parent.Backward.MouseButton1Click:connect(function()
            view = 0
            print(view)
            print("page 1")
            script.Parent.Parent.BasicInfo.Visible = true
            script.Parent.Parent.Face.Visible = false
            script.Parent.Parent.Backward.Visible = false
        end)
    end
end



This script only functions properly when the second if statement is <= 1, but I need it to only equal 1. I checked the output to make sure that this variable is one upon pressing it, but it doesn't do anything.

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

Log in to vote
0
Answered by 4 days ago

Your script isn't working, because it checks what 'view' equals at the start of the script. It's not inside either function, so it won't update if you update the view variable.

This is easy to fix, however.

local nextbutton = script.Parent
local backbutton = script.Parent.Parent.Backward
local info = script.Parent.Parent.BasicInfo
local face = script.Parent.Parent.Face
local view = 0

nextbutton.MouseButton1Click:connect(function()
    if view == 0 then
            view = 1
            print(view)
            print("page 2")
        info.Visible = false
            face.Visible = true
            backbutton.Visible = true
        end
end)

backbutton.MouseButton1Click:connect(function()
    if view == 1 then
            view = 0
            print(view)
            print("page 1")
        info.Visible = true
            face.Visible = false
            backbutton.Visible = false
    end
end)

As you can see, each time you click the button, it will check what view equals. That should be all you need to know.

Ad

Answer this question



Ad