I want to save the highscore created in the game and can be seen in the main menu when the player hits the highscore button, can someone help me?
You can solve your problem in a easier way..
Just declare a Variable for the Score like this..
local score=0
Then Increment the score variable by 1 whenever it hits the paddle. So Insert the coding in Collision Function as given below:
local function onCollision(event)
{
score=score+1
}
ball.collision=onCollision
ball:addEventListener("collision",ball)
Finally When you need to save your highscore (after gameover), You can use Preference instead of json which makes the larger coding.
local preference= require "preference"
local highscore=0
preference.save{highscore=score}
If you want to display the Highscore, then use the following:
highscore_value=preference.getValue("highscore")
display.newText(highscore_value,0,0,nil,30)
This might be useful for your problem !!
you can use SQLITE to save the highscore to database another way is make a file that write the score to a Text File and save it to the directory of the system
Multiple libraries exist for this purpose. GGScore is an open source library built by GlitchGames which can easily allow you to do this: GlitchGames/GGScore
All the documentation you need is in the main page (README.md) so there isn't really a need for me to explain the code. But it's really easy to use.