- the code is for upadeting a book ui
- i am looking to make it faster + easier to read
local Frame = script.Parent
local Seciton1 = Frame.Seciton1
local Seciton2 = Frame.Seciton2
local NextButton = Frame.Next
local BackButton = Frame.Back
local FrameModle = script.Frame
local Page = Frame.Page
local rbx = "rbxassetid://"
local Pages = {
Page1 = {Frame1 = {
text = "جبالي اجا و سلمى",
ImageId = rbx.."18222933997",
Size = UDim2.new(0.944, 0,0.505, 0),
Position = UDim2.new(0.015, 0,0.086, 0)
},Frame2 = {
text ="جديس",
ImageId = rbx.."18222773535",
Size = UDim2.new(0.944, 0,0.505, 0),
Position = UDim2.new(0.066, 0,0.389, 0)
}},
Page2 = {Frame1 = {
text = "جبالي اجا و سلمى2",
ImageId = rbx.."18222933997",
Size = UDim2.new(0.944, 0,0.505, 0),
Position = UDim2.new(0.015, 0,0.086, 0)
},Frame2 = {
text ="جديس2",
ImageId = rbx.."18222773535",
Size = UDim2.new(0.944, 0,0.505, 0),
Position = UDim2.new(0.066, 0,0.389, 0)
}},
}
local legnthOfDictionary = function(dictionary)
local HowManyItems = 0
for i in pairs(dictionary) do
HowManyItems += 1
end
return HowManyItems
end
local MaxPage = legnthOfDictionary(Pages)
local CurrentPage = 1
Page.Text = "صفحه"..tostring(MaxPage).."/"..tostring(CurrentPage)
print(Page)
local Updateing = function(PageFrame,key,IsItFirstTime)
print(PageFrame)
Page.Text = "صفحه"..tostring(MaxPage).."/"..tostring(CurrentPage)
if Seciton1:FindFirstChild("Clone") and not IsItFirstTime then
local Clone = Seciton1:FindFirstChild("Clone")
print(Clone,"Edited?")
Clone.Name = "Clone"
Clone.Position = PageFrame.Position
Clone.Size = PageFrame.Size
Clone:WaitForChild("image").Image = PageFrame.ImageId
Clone:WaitForChild("Name").Text = PageFrame.text
return
elseif Seciton2:FindFirstChild("Clone") and not IsItFirstTime then
print("D")
local Clone = Seciton2:FindFirstChild("Clone")
Clone.Name = "Clone"
Clone.Position = PageFrame.Position
Clone.Size = PageFrame.Size
Clone:WaitForChild("image").Image = PageFrame.ImageId
Clone:WaitForChild("Name").Text = PageFrame.text
return
end
local Clone = FrameModle:Clone()
Clone.Name = "Clone"
Clone.Position = PageFrame.Position
Clone.Size = PageFrame.Size
Clone:WaitForChild("image").Image = PageFrame.ImageId
Clone:WaitForChild("Name").Text = PageFrame.text
print(key)
if key == 1 then
Clone.Parent = Seciton1
else
Clone.Parent = Seciton2
end
end
Updateing(Pages["Page1"].Frame1,1,true)
Updateing(Pages["Page1"].Frame2,2,true)
local NextBackFunction = function(Next)
if Next then
if CurrentPage ~= MaxPage then
CurrentPage += 1
local TargetPage = Pages["Page"..CurrentPage]
for key,PageFrame in pairs(TargetPage) do
if key == "Frame1" then
Updateing(PageFrame,1,false)
else
Updateing(PageFrame,2,false)
end
end
end
else
if CurrentPage ~= 1 then
CurrentPage -= 1
local TargetPage = Pages["Page"..CurrentPage]
for key,PageFrame in pairs(TargetPage) do
if key == "Frame1" then
Updateing(PageFrame,1)
else
Updateing(PageFrame,2)
end
end
end
end
end
NextButton.MouseButton1Click:Connect(function()
NextBackFunction(true)
end)
BackButton.MouseButton1Click:Connect(function()
NextBackFunction(false)
end)
--for Key,Value in pairs(Pages) do
-- for _,FramePropites in pairs(Value) do
-- end
--end
