so, I’m trying to make this system that displays a book GUI with working pages or a Sticky note GUI
that displays text based on StringValues stored into the object the player clicks. The values are passed to the Client trough a RemoteEvent.
There is no issue with the sticky note part of the code, but when it comes to the book, it’s another story, the book only works once, for moving up from pages: 1 and 2 to: 3 and 4 then breaks, also the PageDown function doesn’t work either for some reason, I’ve tried many things before posting the code here and remain Puzzled.
local evn = game.ReplicatedStorage.InteractionEvent
local CurrenLeft = 1
local CurrenRight = 2
local PgRun = false
local Page = {}
local function LoadText(CurrLef, CurrRight, Count)
script.Parent.BookUi.Bckg.PageLeft.Text = Page[CurrLef].Value
script.Parent.BookUi.Bckg.PageRight.Text = Page[CurrRight].Value
print(CurrLef)
print(CurrRight)
print(Count)
if CurrLef == 1 then
script.Parent.BookUi.PgDwn.Visible = false
script.Parent.BookUi.PgUp.Visible = true
elseif CurrRight == Count then
script.Parent.BookUi.PgUp.Visible = false
script.Parent.BookUi.PgDwn.Visible = true
else
script.Parent.BookUi.PgUp.Visible = true
script.Parent.BookUi.PgDwn.Visible = true
end
end
local function PageUp(CurentLeft, CurentRight, PageCount)
if script.Parent.BookUi.Visible == true and CurentRight ~= PageCount and PgRun == true then
print("UpRan")
script["Book Page Turn"]:Play()
CurentLeft, CurentRight = (CurentRight + 1), (CurentLeft + 3)
LoadText(CurentLeft, CurentRight, PageCount)
end
end
local function PageDown(CurentLeft, CurentRight, PageCount)
if script.Parent.BookUi.Visible == true and CurentLeft ~= 1 and PgRun == true then
print("DwnRan")
script["Book Page Turn"]:Play()
CurentLeft, CurentRight = CurentLeft - 1, CurentRight - 3
LoadText(CurentLeft, CurentRight, PageCount)
end
end
local function Exit(CurrenLeft, CurrenRight)
--script.Parent.Enabled = false
script.Parent.BookUi.Visible = false
CurrenLeft = 1
CurrenRight = 2
end
evn.OnClientEvent:Connect(function(ReadType, Pages, NoteText)
print("Event Recieved")
if ReadType.Value == 1 then
print("ReadType is 1(book)")
local PageCount = #Pages
Page = Pages
print("Table set")
--script.Parent.Enabled = true
-- wait()
script.Parent.BookUi.Visible = true
script.Parent.NoteUi.Visible = false
LoadText(CurrenLeft, CurrenRight, PageCount)
print("rendering text")
script.Parent.BookUi.PgUp.MouseButton1Down:Connect(function() PgRun = true PageUp(CurrenLeft, CurrenRight, PageCount) wait() PgRun = false end)
script.Parent.BookUi.PgDwn.MouseButton1Down:Connect(function() PgRun = true PageDown(CurrenLeft, CurrenRight, PageCount) wait() PgRun = false end)
script.Parent.BookUi.Bckg.ExitButton.MouseButton1Click:Connect(function() Exit(CurrenLeft, CurrenRight) end)
elseif ReadType.Value == 2 then
print("ReadType is 2(sticky note)")
script.Parent.NoteUi.Visible = true
script.Parent.BookUi.Visible = false
script.Parent.NoteUi.ImageLabel.NoteText.Text = NoteText.Value
script.Parent.NoteUi.ImageLabel.ExitButton.MouseButton1Click:Connect(function()
script.Parent.NoteUi.Visible = false
end)
end
end)
(Note that the code is extremely messy as I wasn’t going for OOP and am far from a professional)
I’ll be awaiting any help at all, thank you in advance.