Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My next page gui won't work?

Asked by
Relatch 550 Moderation Voter
9 years ago

Explanation

My gui is made to switch between 2 pages when someone clicks next/previous. This is just added on to my shop gui, which isn't relevant.


Problem

This works, but for some reason I need to click twice when switching between pages. This can cause confusion, and people may think it's broken.


Code [First is for the next button, and the second is for the previous button.]

npopen = false

script.Parent.MouseButton1Down:connect(function()
    if npopen == false then
        npopen = true
        script.Parent.BackgroundColor3 = Color3.new(100/255, 100/255, 100/255)
        script.Parent.Parent.Previous.BackgroundColor3 = Color3.new(0, 0, 0)
        script.Parent.Parent.NextPage.Visible = true
    elseif npopen == true then
        npopen = false
        print('already open')
    end
end)
local popen = false

script.Parent.MouseButton1Down:connect(function()
    if popen == false then
        popen = true
        script.Parent.BackgroundColor3 = Color3.new(100/255, 100/255, 100/255)
        script.Parent.Parent.Next.BackgroundColor3 = Color3.new(0, 0, 0)
        script.Parent.Parent.NextPage.Visible = false
    elseif popen == true then
        popen = false
        print('already closed')
    end
end)

Links

http://prntscr.com/7mcvak

http://www.roblox.com/shopthing-item?id=263133147

2 answers

Log in to vote
1
Answered by 9 years ago

If it is just changing the page, why do you have a debounce? Just remove the debounce and you should be fine :)

Ad
Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

Your problem is very simple. When you set your isNext variable, you already put .Value. Therefore, it's going to save the value what it currently is. In other words, it won't keep updating the variable, whenever the BoolValue changes. The way to fix this is by removing .Value from where you declare the isNext variable, and whenever you're comparing it or setting it as a new value, add .Value. Here are your scripts:

wait(2)
local isNext = script.Parent.IsNext

script.Parent.InputBegan:connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        if isNext.Value == true then
            script.Parent.BackgroundColor3 = Color3.new(100/255, 100/255, 100/255)
            script.Parent.Parent.Previous.BackgroundColor3 = Color3.new(0, 0, 0)
            script.Parent.Parent.NextPage.Visible = true
            isNext.Value = false
        elseif isNext.Value == false then
            print('Already open')
        end
    end
end)
wait(2)
local isNext = script.Parent.IsNext

script.Parent.InputBegan:connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
      if isNext.Value == false then
            script.Parent.BackgroundColor3 = Color3.new(100/255, 100/255, 100/255)
            script.Parent.Parent.Next.BackgroundColor3 = Color3.new(0, 0, 0)
            script.Parent.Parent.NextPage.Visible = false
            isNext.Value = true
        elseif isNext.Value == true then
            print('Already closed')
        end
    end
end)

Answer this question