Trouble knowing when reaching end of page

I’ve basically got 2 buttons for going up and down on a page, however they don’t change colors as the pages get changed

local Page = 1
local MaxPages = #Pages:GetChildren() - 2 -- minus 2 because I have 2 UIElements that arent part of the pages

Next.Activated:Connect(function()
	if Page < MaxPages then
		Next.ImageColor3 = Color3.fromRGB(56, 186, 255)
		Page = Page + 1
		PageLayout:Next()
		
		if Page > 1 then
			if Page == MaxPages then
				Next.ImageColor3 = Color3.fromRGB(100, 100, 100)
			else
				Next.ImageColor3 = Color3.fromRGB(56, 186, 255)	
			end	
		end
	else
		Next.ImageColor3 = Color3.fromRGB(100, 100, 100)
	end
end)

Previous.Activated:Connect(function()
	if Page > 1 then
		Previous.ImageColor3 = Color3.fromRGB(56, 186, 255)
		Page = Page - 1
		PageLayout:Previous()
		
		if Page < MaxPages then
			if Page == 1 then
				Previous.ImageColor3 = Color3.fromRGB(100, 100, 100)
			else
				Previous.ImageColor3 = Color3.fromRGB(56, 186, 255)	
			end	
		end
	else
		Previous.ImageColor3 = Color3.fromRGB(100, 100, 100)
	end
end)

When I go down one, the top button doesn’t go blue (to signify you can go back up)
robloxapp-20190921-1002376

1 Like

Is there any error?
30 chars 30

No errors

And when you write the line for changing color into console, does it work

Both “Next” and “Previous” are subtracting 1 from page, rather than one of them subtracting 1 while the other adds 1.

Just noticed that and updated my code to what I currently have (still doesn’t work tho)

You only set the color when you click it.

Instead check for both whenever you click one.

local Page = 1
local MaxPages = #Pages:GetChildren()-2

Next.Activated:Connect(function()
    if Page < MaxPages then
        Page = Page + 1
        PageLayout:Next()
        if Page == MaxPages then
            Next.ImageColor3 = Color3.fromRGB(100,100,100)
        elseif Page == 2 then
            Previous.ImageColor3 = Color3.fromRGB(56,186,255)
        end
    end
end)

Previous.Activated:Connect(function()
    if Page > 1 then
        local prev = Page
        Page = Page - 1
        PageLayout:Previous()
        if Page == 1 then
            Previous.ImageColor3 = Color3.fromRGB(100,100,100)
        elseif prev == MaxPages then
            Next.ImageColor3 = Color3.fromRGB(56,186,255)
        end
    end
end)
1 Like