Flipped page not returning

i have a script for a flipping page animation thing
it works once but it breaks after

code here

local tweenservice = game:GetService("TweenService")

local Folder = script.Parent
local pages = Folder.Pages
local left = Folder.Left
local right = Folder.Right
local lyscale = left.Size.Y.Scale
local ryscale = right.Size.Y.Scale

local debounce = false
local bonce = false

local page_number = 1

function open(page)
	local p = page.Size.Width.Scale
	local q = page.Size.Height.Scale
	
	bonce = true
	
	local width = 0
	
	for i = 0, 180, 1.5 do
		task.wait()
		width = math.cos(math.rad(i))
		page.Size = UDim2.fromScale(p * width,q)
	end
	bonce = false
end

function close(page)
	local p = page.Size.Width.Scale
	local q = page.Size.Height.Scale
	
	bonce = true

	local width = 0

	for i = 180, 0, -1.5 do
		task.wait()
		width = math.cos(math.rad(i))
		page.Size = UDim2.fromScale(p * width,q)
		print(p*width)
	end
	bonce = false
end

left.MouseButton1Click:Connect(function(player)
	local page = pages[page_number]
	
	if bonce then
		return
	end
	
	open(page)
	page_number = math.clamp(page_number + 1, 1, 3)  
end)

right.MouseButton1Click:Connect(function(player)
	local page = pages[page_number]
	
	if bonce then
		return
	end
	
	close(page)
	page_number = math.clamp(page_number - 1, 1, 3) 
end)

i dont know whats wrong

Because you’re multiplying two negative numbers, the result is a positive scale.

function close(page)
	local p = page.Size.Width.Scale
	local q = page.Size.Height.Scale
	
	bonce = true

	local width = 0

	for i = 180, 0, -1.5 do
		task.wait()
		width = math.cos(math.rad(i))
		page.Size = UDim2.fromScale(p * width*-1,q)
		print(p*width)
	end
	bonce = false
end
1 Like