I’m trying to make a recipe book where you can click the left and right buttons to go through the different recipes. Unfortunately for some reason when I click right and then left one after the other it messes up the order and results in two recipes being shown on the screen (as shown in the image)
Here is the left button:
local page = script.Parent.Parent
local pageNumber = page:GetAttribute("page")
script.Parent.MouseButton1Click:Connect(function()
print("left click")
if pageNumber == 1 then
print(pageNumber)
script.Parent.Parent["Caffeine Recipes"]:TweenPosition(UDim2.new(2, 0, 0.447, 0))
script.Parent.Parent["Drinks Recipes"].Position = UDim2.new(-2,0,0.37,0)
script.Parent.Parent["Drinks Recipes"]:TweenPosition(UDim2.new(0.5, 0, 0.37, 0))
pageNumber = 3
elseif pageNumber == 2 then
print(pageNumber)
script.Parent.Parent["Dessert Recipes"]:TweenPosition(UDim2.new(2, 0, 0.37, 0))
script.Parent.Parent["Caffeine Recipes"].Position = UDim2.new(-2,0,0.447,0)
script.Parent.Parent["Caffeine Recipes"]:TweenPosition(UDim2.new(0.5, 0, 0.447, 0))
pageNumber = 1
elseif pageNumber == 3 then
print(pageNumber)
script.Parent.Parent["Drinks Recipes"]:TweenPosition(UDim2.new(2, 0, 0.37, 0))
script.Parent.Parent["Dessert Recipes"].Position = UDim2.new(-2,0,0.37,0)
script.Parent.Parent["Dessert Recipes"]:TweenPosition(UDim2.new(0.5, 0, 0.37, 0))
pageNumber = 2
end
end)
Here is the right button:
local page = script.Parent.Parent
local pageNumber = page:GetAttribute("page")
script.Parent.MouseButton1Click:Connect(function()
print("right click")
if pageNumber == 1 then
print(pageNumber)
script.Parent.Parent["Caffeine Recipes"]:TweenPosition(UDim2.new(-2, 0, 0.447, 0))
script.Parent.Parent["Dessert Recipes"].Position = UDim2.new(2,0,0.37,0)
script.Parent.Parent["Dessert Recipes"]:TweenPosition(UDim2.new(0.5, 0, 0.37, 0))
pageNumber = 2
elseif pageNumber == 2 then
print(pageNumber)
script.Parent.Parent["Dessert Recipes"]:TweenPosition(UDim2.new(-2, 0, 0.37, 0))
script.Parent.Parent["Drinks Recipes"].Position = UDim2.new(2,0,0.37,0)
script.Parent.Parent["Drinks Recipes"]:TweenPosition(UDim2.new(0.5, 0, 0.37, 0))
pageNumber = 3
elseif pageNumber == 3 then
print(pageNumber)
script.Parent.Parent["Drinks Recipes"]:TweenPosition(UDim2.new(-2, 0, 0.37, 0))
script.Parent.Parent["Caffeine Recipes"].Position = UDim2.new(2,0,0.447,0)
script.Parent.Parent["Caffeine Recipes"]:TweenPosition(UDim2.new(0.5, 0, 0.447, 0))
pageNumber = 1
end
end)
This is the current output:
15:20:35.456 right click - Client - LocalScript:5
15:20:35.457 1 - Client - LocalScript:7
15:20:37.205 left click - Client - LocalScript:5
15:20:37.205 1 - Client - LocalScript:7
The attribute starts at page 1 (caffeine)
Thank you for your help!