I am writing a script to switch between pages for a Spell Book. When I try to switch pages, the code I think should work throws an error saying:
Players.smash1975.PlayerGui.SpellBook.RightFrame.Back.Handler:68: attempt to call a number value
The line which is throwing the error is:
button.Parent.SpellsL.Text = getPage(page,0)
The function "getPage" is:
function getPage(page,side)
if tonumber(page) >= -1000 then
-- Page is a number (Is hardcoded so always should be)
local p = pages
for x=1,#p,1 do
if side == 1 then
if p[x] == (page+math.floor(side)(page-1)) then
-- Found correct page
local ret = ""
local c = p[x+1]
for i=1,#c,1 do -- Convert list to string
ret = ret..c[i].."\n"
end
return ret -- return string
end
else
if p[x] == (page) then
-- Found correct page
local ret = ""
local c = p[x+1]
for i=1,#c,1 do -- Convert list to string
ret = ret..c[i].."\n"
end
return ret -- return string
end
end
end
end
return "" -- Something went wrong, return empty string
end
The error is being throw when I try to call "page" to alter the position in the list that I get the string from. (Line 7)

1 comment
Originally, I did not separate the code into if side == 1 and else, but I was just trying to see if the value of 0 was the issue. It is not.