Hii rob, i have completely re-wrote my code & level loading & reloading is working fine but a small issue, when player dies & over screen is loaded i click reload button & the level1 reloads but next time when player dies the over screen isn’t loading 
level_a file code:
--creating level1 scene local composer=require("composer") local scene=composer.newScene("level\_a") function scene:create( event ) end function scene:show( event ) end function scene:destroy( event ) end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) local physics local tPrevious --game variables local scoretext \_G.ccount=0 local shut local mytime local ctimer local bgspeed local rspeed local allow local kill local collisionFilter local ovtimer local sgroup --local intro = audio.loadSound( "images/rintro.mp3" ) --local theme = audio.play( intro, { channel=1, loops=-1 } ) --local csound=audio.loadSound("images/coins.mp3") --local cplay --ocal deathsound=audio.loadSound("images/death.mp3") --local dplay --adding centering position variables local x local y --adding background local bgtile, bbgtile --adding runnning tile local rtile, rrtile --adding player animations local options local psheet local sequenceData --adding player local player --bird data local boptions local bsheet local bdata --adding bird local bfilter local bird --adding player base to stand on local base --adding base to bird local bbase --adding stopper to destroy out of bound objects local stopper --creating coins group local climit local coinsg local cstatus --function to deal obs collision local function obscols( self,event ) if(event.phase=="began") then --print(event.other.myName) if (self.myName=='stack1') then obs[1].isVisible=false obs[1].isAlive=false elseif (self.myName=='stack2') then obs[2].isVisible=false obs[2].isAlive=false elseif (self.myName=='stack3') then obs[3].isVisible=false obs[3].isAlive=false elseif (self.myName=='stack4') then obs[4].isVisible=false obs[4].isAlive=false elseif (self.myName=='stack5') then obs[5].isVisible=false obs[5].isAlive=false elseif (self.myName=='stack6') then obs[6].isVisible=false obs[6].isAlive=false elseif (self.myName=='stack7') then obs[7].isVisible=false obs[7].isAlive=false elseif (self.myName=='stack8') then obs[8].isVisible=false obs[8].isAlive=false elseif (self.myName=='stack9') then obs[9].isVisible=false obs[9].isAlive=false elseif (self.myName=='stack10') then obs[10].isVisible=false obs[10].isAlive=false elseif (self.myName=='stack11') then obs[11].isVisible=false obs[11].isAlive=false elseif (self.myName=='stack12') then obs[12].isVisible=false obs[12].isAlive=false elseif (self.myName=='stack13') then obs[13].isVisible=false obs[13].isAlive=false elseif (self.myName=='stack14') then obs[14].isVisible=false obs[14].isAlive=false elseif (self.myName=='stack15') then obs[15].isVisible=false obs[15].isAlive=false elseif (self.myName=='stack16') then obs[16].isVisible=false obs[16].isAlive=false elseif (self.myName=='stack17') then obs[17].isVisible=false obs[17].isAlive=false elseif (self.myName=='stack18') then obs[18].isVisible=false obs[18].isAlive=false elseif (self.myName=='stack19') then obs[19].isVisible=false obs[19].isAlive=false elseif (self.myName=='stack20') then obs[20].isVisible=false obs[20].isAlive=false elseif (self.myName=='stack21') then obs[21].isVisible=false obs[21].isAlive=false elseif (self.myName=='stack22') then obs[22].isVisible=false obs[22].isAlive=false elseif (self.myName=='stack23') then obs[23].isVisible=false obs[23].isAlive=false elseif (self.myName=='stack24') then obs[24].isVisible=false obs[24].isAlive=false --coins handling elseif (event.other.myName=='coin\_num1') then coinsg[1].isVisible=false coinsg[1].isAlive=false elseif (event.other.myName=='coin\_num2') then coinsg[2].isVisible=false coinsg[2].isAlive=false elseif (event.other.myName=='coin\_num3') then coinsg[3].isVisible=false coinsg[3].isAlive=false elseif (event.other.myName=='coin\_num4') then coinsg[4].isVisible=false coinsg[4].isAlive=false elseif (event.other.myName=='coin\_num5') then coinsg[5].isVisible=false coinsg[5].isAlive=false elseif (event.other.myName=='coin\_num6') then coinsg[6].isVisible=false coinsg[6].isAlive=false elseif (event.other.myName=='coin\_num7') then coinsg[7].isVisible=false coinsg[7].isAlive=false elseif (event.other.myName=='coin\_num8') then coinsg[8].isVisible=false coinsg[8].isAlive=false elseif (event.other.myName=='coin\_num9') then coinsg[9].isVisible=false coinsg[9].isAlive=false elseif (event.other.myName=='coin\_num10') then coinsg[10].isVisible=false coinsg[10].isAlive=false elseif (event.other.myName=='coin\_num11') then coinsg[11].isVisible=false coinsg[11].isAlive=false elseif (event.other.myName=='coin\_num12') then coinsg[12].isVisible=false coinsg[12].isAlive=false elseif (event.other.myName=='coin\_num13') then coinsg[13].isVisible=false coinsg[13].isAlive=false elseif (event.other.myName=='coin\_num14') then coinsg[14].isVisible=false coinsg[14].isAlive=false elseif (event.other.myName=='coin\_num15') then coinsg[15].isVisible=false coinsg[15].isAlive=false elseif (event.other.myName=='coin\_num16') then coinsg[16].isVisible=false coinsg[16].isAlive=false elseif (event.other.myName=='coin\_num17') then coinsg[17].isVisible=false coinsg[17].isAlive=false elseif (event.other.myName=='coin\_num18') then coinsg[18].isVisible=false coinsg[18].isAlive=false elseif (event.other.myName=='coin\_num19') then coinsg[19].isVisible=false coinsg[19].isAlive=false elseif (event.other.myName=='coin\_num20') then coinsg[20].isVisible=false coinsg[20].isAlive=false elseif (event.other.myName=='coin\_num21') then coinsg[21].isVisible=false coinsg[21].isAlive=false elseif (event.other.myName=='coin\_num22') then coinsg[22].isVisible=false coinsg[22].isAlive=false elseif (event.other.myName=='coin\_num23') then coinsg[23].isVisible=false coinsg[23].isAlive=false elseif (event.other.myName=='coin\_num24') then coinsg[24].isVisible=false coinsg[24].isAlive=false end --composer.gotoScene( "level2",{ effect = "fade", time = 3000 } ) end end --function to move tiles local function movet(event) local tDelta = event.time - tPrevious tPrevious = event.time local xOffset = ( 0.05 \* tDelta ) bbgtile.x=bbgtile.x-xOffset\*bgspeed bgtile.x=bgtile.x-xOffset\*bgspeed rtile.x=rtile.x-xOffset\*rspeed rrtile.x=rrtile.x-xOffset\*rspeed if bgtile.x \< -480 + bgtile.width / 2 then bgtile:translate(480\*2 , 0) elseif bbgtile.x \< -480 + bbgtile.width / 2 then bbgtile:translate(480\*2 , 0) elseif rtile.x\<-480 +rtile.width / 2 then rtile:translate( 480\*2, 0 ) elseif rrtile.x\<-480 + rrtile.width / 2 then rrtile:translate( 480\*2, 0 ) end end --function to deal coins group pooling local function getcoin() for j=1, #coinsg do if not coinsg[j].isAlive then return coinsg[j] end end return nil end --function to deal ob1 group pooling local function getobs() local somerand=math.random( 1,24 ) --calling ob1 from pool for i=1, #obs do if not obs[somerand].isAlive then return obs[somerand] end end return nil end -- --independent coin spawning function local function spcoin() local c\_elem = require("mydata") c\_elem.new=getcoin() if(c\_elem.new~=nil) then c\_elem.new.isVisible=true c\_elem.new.isAlive=true c\_elem.new.isBodyActive=true c\_elem.new.x=485 c\_elem.new.y=140 --adding event listener for each coin c\_elem.new:setLinearVelocity(-100,0) c\_elem.new.collision=cclean c\_elem.new:addEventListener("collision",c\_elem.new) end end --independent obstacles spawning function local function spobs() local obs\_elem = require("mydata") obs\_elem.new=getobs() if(obs\_elem.new~=nil) then obs\_elem.new.isVisible=true obs\_elem.new.isAlive=true obs\_elem.new.isBodyActive=true obs\_elem.new.isFixedRotation=true obs\_elem.new.x=math.random( 480,490 ) obs\_elem.new.y=252 --adding event listener for each coin obs\_elem.new:setLinearVelocity(-250,0) obs\_elem.new.collision=obscols obs\_elem.new:addEventListener("collision",obs\_elem.new) end end --tile speed controlling function local function setspeed( event ) if mytime==120 then bgspeed=bgspeed+0.05 rspeed=rspeed+0.5 elseif mytime\>140 then mytime=0 end end -- --function to decide obstacle spawning local function obdecide(event) if(shut==0) then if (mytime==100) then spobs() elseif (mytime\>100) then mytime=0 end end end --function to spawn coins local function cdecide(event) if(shut==0) then if(ctimer==15) then spcoin() elseif(ctimer==30) then spcoin() elseif(ctimer==45) then spcoin() elseif(ctimer==60) then spcoin() elseif(ctimer==75) then spcoin() elseif(ctimer\>90) then ctimer=0 end end end local function cleanalla(event) sgroup:removeSelf() sgroup=nil player.collision=nil stopper.collision=nil bird.collision=nil Runtime:removeEventListener( "tap", jump) --Runtime:removeEventListener("enterFrame",move) player:removeEventListener("collision",player) stopper:removeEventListener( "collision", stopper) bird:removeEventListener("collision",bird) print("destroyed") end --player collision event with base & obstacles local function colls(self,event) if(event.phase=="began") then --print(self.myName) --print(event.other.myName) if(self.myName=="hero" and event.other.myName=="base") then player:setSequence("run") player:play() bird:play() allow=1 else --handle player death function shut=1 print("player dead") --pdead() --composer.gotoScene("level2",false) end end end local function sdisp() \_G.ccount=\_G.ccount+1 scoretext.text=" x "..\_G.ccount --cplay=audio.play( csound, { channel=0, loops=0 } ) end --coin collision with bird local function cclean(self,event) if(event.phase=="began") then --print("got here") --print(event.other.myName) if (event.other.myName=='coin\_num1') then coinsg[1].isVisible=false coinsg[1].isAlive=false sdisp() elseif (event.other.myName=='coin\_num2') then coinsg[2].isVisible=false coinsg[2].isAlive=false sdisp() elseif (event.other.myName=='coin\_num3') then coinsg[3].isVisible=false coinsg[3].isAlive=false sdisp() elseif (event.other.myName=='coin\_num4') then coinsg[4].isVisible=false coinsg[4].isAlive=false sdisp() elseif (event.other.myName=='coin\_num5') then coinsg[5].isVisible=false coinsg[5].isAlive=false sdisp() elseif (event.other.myName=='coin\_num6') then coinsg[6].isVisible=false coinsg[6].isAlive=false sdisp() elseif (event.other.myName=='coin\_num7') then coinsg[7].isVisible=false coinsg[7].isAlive=false sdisp() elseif (event.other.myName=='coin\_num8') then coinsg[8].isVisible=false coinsg[8].isAlive=false sdisp() elseif (event.other.myName=='coin\_num9') then coinsg[9].isVisible=false coinsg[9].isAlive=false sdisp() elseif (event.other.myName=='coin\_num10') then coinsg[10].isVisible=false coinsg[10].isAlive=false sdisp() elseif (event.other.myName=='coin\_num11') then coinsg[11].isVisible=false coinsg[11].isAlive=false sdisp() elseif (event.other.myName=='coin\_num12') then coinsg[12].isVisible=false coinsg[12].isAlive=false sdisp() elseif (event.other.myName=='coin\_num13') then coinsg[13].isVisible=false coinsg[13].isAlive=false sdisp() elseif (event.other.myName=='coin\_num14') then coinsg[14].isVisible=false coinsg[14].isAlive=false sdisp() elseif (event.other.myName=='coin\_num15') then coinsg[15].isVisible=false coinsg[15].isAlive=false sdisp() elseif (event.other.myName=='coin\_num16') then coinsg[16].isVisible=false coinsg[16].isAlive=false sdisp() elseif (event.other.myName=='coin\_num17') then coinsg[17].isVisible=false coinsg[17].isAlive=false sdisp() elseif (event.other.myName=='coin\_num18') then coinsg[18].isVisible=false coinsg[18].isAlive=false sdisp() elseif (event.other.myName=='coin\_num19') then coinsg[19].isVisible=false coinsg[19].isAlive=false sdisp() elseif (event.other.myName=='coin\_num20') then coinsg[20].isVisible=false coinsg[20].isAlive=false sdisp() elseif (event.other.myName=='coin\_num21') then coinsg[21].isVisible=false coinsg[21].isAlive=false sdisp() elseif (event.other.myName=='coin\_num22') then coinsg[22].isVisible=false coinsg[22].isAlive=false sdisp() elseif (event.other.myName=='coin\_num23') then coinsg[23].isVisible=false coinsg[23].isAlive=false sdisp() elseif (event.other.myName=='coin\_num24') then coinsg[24].isVisible=false coinsg[24].isAlive=false sdisp() end end end --function to make player jump when screen is tapped local function jump(event) if allow==1 and shut==0 then player:setLinearVelocity( 0, -400 ) player:setSequence("lup") bird:setLinearVelocity(0,-400) bird:pause() allow=0 end return true end function addassets(event) print("i got called") -- important libs loading physics=require( "physics" ) tPrevious = system.getTimer() --game variables shut=0 mytime=0 ctimer=0 ovtimer=0 bgspeed = 0.6 rspeed = 4.5 allow=0 kill = 0 collisionFilter = { groupIndex = -2 } --intro = audio.loadSound( "images/rintro.mp3" ) --theme = audio.play( intro, { channel=1, loops=-1 } ) physics.start( ) physics.setGravity( 0, 36) --adding centering position variables x = display.contentCenterX y = display.contentCenterY --adding player animations options= { frames = { { x = 0, y = 188, width = 28, height = 45, sourceX=0, sourceY=0, sourceWidth=28 , sourceHeight=45 }, { x = 0, y = 94, width = 31, height = 45, sourceX=0, sourceY=0, sourceWidth=31 , sourceHeight=45 }, { x = 0, y = 0, width = 37, height = 45, sourceX=0, sourceY=0, sourceWidth=37 , sourceHeight=45 }, { x = 0, y = 47, width = 33, height = 45, sourceX=0, sourceY=0, sourceWidth=33 , sourceHeight=45 }, { x = 0, y = 141, width = 30, height = 45, sourceX=0, sourceY=0, sourceWidth=30 , sourceHeight=45 }, { x = 30, y = 188, width = 25, height = 45, sourceX=0, sourceY=0, sourceWidth=25 , sourceHeight=45 }, { x = 35, y = 47, width = 20, height = 45, sourceX=0, sourceY=0, sourceWidth=20 , sourceHeight=45 }, { x = 33, y = 94, width = 20, height = 45, sourceX=0, sourceY=0, sourceWidth=20 , sourceHeight=45 }, { x = 32, y = 141, width = 23, height = 45, sourceX=0, sourceY=0, sourceWidth=23 , sourceHeight=45 } }, sheetContentWidth = 64, sheetContentHeight = 256 } psheet=graphics.newImageSheet( "images/sprites.png", options ) sequenceData = { {name="run", start=1, count=9, time=250}, {name="lup", start=7, count=1} } --bird data boptions= { frames = { { x = 0, y = 28, width = 28, height = 19, sourceX=2, sourceY=0, sourceWidth=35 , sourceHeight=30 }, { x = 0, y = 12, width = 33, height = 14, sourceX=2, sourceY=5, sourceWidth=35 , sourceHeight=30 }, { x = 0, y = 0, width = 33, height = 10, sourceX=2, sourceY=11, sourceWidth=35 , sourceHeight=30 }, { x = 30, y = 28, width = 28, height = 18, sourceX=2, sourceY=11, sourceWidth=35 , sourceHeight=30 }, { x = 60, y = 17, width = 24, height = 20, sourceX=4, sourceY=10, sourceWidth=35 , sourceHeight=30 }, { x = 30, y = 48, width = 26, height = 14, sourceX=2, sourceY=11, sourceWidth=35 , sourceHeight=30 }, { x = 0, y = 49, width = 26, height = 8, sourceX=2, sourceY=10, sourceWidth=35 , sourceHeight=30 }, { x = 35, y = 0, width = 25, height = 15, sourceX=3, sourceY=4, sourceWidth=35 , sourceHeight=30 } }, sheetContentWidth = 128, sheetContentHeight = 64 } bsheet=graphics.newImageSheet( "images/bsheet.png", boptions ) bdata = { {name="fly", start=1, count=8, time=600}, } --adding bird bfilter={ groupIndex = -4 } --creating coins group climit=24 coinsg={} --creating obstacles group obslimit=24 obs={} sgroup = display.newGroup() bgtile = display.newImage( "images/bgtile.png",x,y) sgroup:insert(bgtile) bbgtile=display.newImage( "images/bgtile.png", x+480 ,y) sgroup:insert(bbgtile) rtile=display.newImage( "images/rtile.png", x ,y+122 ) sgroup:insert(rtile) rrtile=display.newImage( "images/rtile.png", x+480, y+122 ) sgroup:insert(rrtile) --adding player base to stand on base=display.newImage( "images/base.png", 80,272 ) sgroup:insert(base) physics.addBody( base, "static",{ bounce=0.0, friction=1,filter=collisionFilter}) base.isVisible=false base.myName="base" --adding base to bird bbase=display.newImage("images/bbase.png",80,150) sgroup:insert(bbase) physics.addBody(bbase,"static",{bounce=0.0,friction=1,filter=collisionFilter}) bbase.isVisible=false bbase.myName="bbase" cstatus=display.newImage("images/cstatus.png",400,50) sgroup:insert(cstatus) scoretext=display.newText(" x 0",430,50, native.systemFont, 14) sgroup:insert(scoretext) scoretext:setFillColor(1,0,0) --adding stopper to destroy out of bound objects stopper=display.newImage( "images/stopper.png", -20,158 ) sgroup:insert(stopper) physics.addBody( stopper, "static", {bounce=0.0,friction=1,gravityScale=0,filter=bfilter} ) stopper.myName="stopper" stopper.isVisible=false --coins setter lines seta=display.newRect(1,128,1200,1) sgroup:insert(seta) physics.addBody(seta,"static",{friction=0,bounce=0.0,filter=bfilter}) seta.isVisible=false setb=display.newRect(1,150,1200,1) sgroup:insert(setb) physics.addBody(setb,"static",{friction=0,bounce=0.0,filter=bfilter}) setb.isVisible=false for j=1,climit do coinsg[j]=display.newImage( "images/coin.png", 250,250 ) sgroup:insert(coinsg[j]) coinsg[j].isVisible=false coinsg[j].isAlive=false physics.addBody( coinsg[j], "dynamic", {friction=0,bounce=0.0,filter=collisionFilter,density=0}) coinsg[j].myName="coin\_num"..j coinsg[j].gravityScale=0 coinsg[j].isBodyActive=false end obs[1]=display.newImage( "images/ob1.png", 250,250 ) obs[2]=display.newImage( "images/ob2.png", 250,250 ) obs[3]=display.newImage( "images/ob3.png", 250,250 ) obs[4]=display.newImage( "images/ob4.png", 250,250 ) obs[5]=display.newImage( "images/ob1.png", 250,250 ) obs[6]=display.newImage( "images/ob2.png", 250,250 ) obs[7]=display.newImage( "images/ob3.png", 250,250 ) obs[8]=display.newImage( "images/ob4.png", 250,250 ) obs[9]=display.newImage( "images/ob1.png", 250,250 ) obs[10]=display.newImage( "images/ob2.png", 250,250 ) obs[11]=display.newImage( "images/ob3.png", 250,250 ) obs[12]=display.newImage( "images/ob4.png", 250,250 ) obs[13]=display.newImage( "images/ob1.png", 250,250 ) obs[14]=display.newImage( "images/ob2.png", 250,250 ) obs[15]=display.newImage( "images/ob3.png", 250,250 ) obs[16]=display.newImage( "images/ob4.png", 250,250 ) obs[17]=display.newImage( "images/ob1.png", 250,250 ) obs[18]=display.newImage( "images/ob2.png", 250,250 ) obs[19]=display.newImage( "images/ob3.png", 250,250 ) obs[20]=display.newImage( "images/ob4.png", 250,250 ) obs[21]=display.newImage( "images/ob1.png", 250,250 ) obs[22]=display.newImage( "images/ob2.png", 250,250 ) obs[23]=display.newImage( "images/ob3.png", 250,250 ) obs[24]=display.newImage( "images/ob4.png", 250,250 ) sgroup:insert(obs[1]) sgroup:insert(obs[2]) sgroup:insert(obs[3]) sgroup:insert(obs[4]) sgroup:insert(obs[5]) sgroup:insert(obs[6]) sgroup:insert(obs[7]) sgroup:insert(obs[8]) sgroup:insert(obs[9]) sgroup:insert(obs[10]) sgroup:insert(obs[11]) sgroup:insert(obs[12]) sgroup:insert(obs[13]) sgroup:insert(obs[14]) sgroup:insert(obs[15]) sgroup:insert(obs[16]) sgroup:insert(obs[17]) sgroup:insert(obs[18]) sgroup:insert(obs[19]) sgroup:insert(obs[20]) sgroup:insert(obs[21]) sgroup:insert(obs[22]) sgroup:insert(obs[23]) sgroup:insert(obs[24]) for i=1,obslimit do obs[i].isVisible=false obs[i].isAlive=false physics.addBody( obs[i], "dynamic", {friction=1,bounce=0.0,filter=collisionFilter}) obs[i].myName="stack"..i obs[i].gravityScale=0 obs[i].isBodyActive=false end player=display.newSprite( psheet, sequenceData) player.x=80 player.y=248 sgroup:insert(player) player:setSequence( "run" ) player:play() physics.addBody( player, "dynamic",{ friction=1,density=100 } ) player.myName="hero" bird=display.newSprite(bsheet,bdata ) bird.x=88 bird.y=140 sgroup:insert(bird) bird:setSequence( "fly" ) bird:play() physics.addBody( bird, "dynamic",{ friction=1 ,bounce=0.0, filter=bfilter,density=100} ) bird.myName="bird" player.collision=colls player:addEventListener("collision",player) bird.collision=cclean bird:addEventListener("collision",bird) stopper.collision=obscols stopper:addEventListener( "collision", stopper) Runtime:addEventListener( "tap", jump ); end addassets(event) --game update loop local function move(event) if(shut==0) then ctimer=ctimer+1 mytime=mytime+1 --setspeed(event) movet(event) obdecide(event) cdecide(event) elseif(shut==1) then ctimer=0 mytime=0 ovtimer=ovtimer+1 physics.pause() player.isVisible=false bird.isVisible=false if(ovtimer==100) then cleanalla(event) elseif(ovtimer\>150) then composer.gotoScene("over") --ovtimer=0 --relevel\_a(event) end end end --game update loop event Runtime:addEventListener( "enterFrame", move ); return scene
over file code
local composer=require("composer") local scene=composer.newScene("over") local function reload( event ) end function scene:create( event ) end function scene:show( event ) end function scene:destroy( event ) end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "destroy", scene ) -- local widget=require("widget") local ovgroup local ovscreen local x = display.contentCenterX local y = display.contentCenterY local cctext local hctext local tctext local retrybutt local mainbutt local function init(event) local mode=event.target.id if(mode==retry) then ovgroup:removeSelf() ovgroup=nil addassets(event) retrybutt:removeEventListener("touch",init) elseif(mode==mainmenu) then print("went to main menu") end return true end function relevel\_a(event) ovgroup=display.newGroup() ovscreen=display.newImage("images/ovscreen.jpg",x,y) --ovscreen=display.newImage("images/gtitle.jpg",x,y) ovgroup:insert(ovscreen) cctext=display.newText(" X 0",248,88, native.systemFont, 14) ovgroup:insert(cctext) cctext.text=" x "..\_G.ccount cctext:setFillColor(1,0,0) retrybutt=display.newImage("images/retry.png",240,250) retrybutt.id=retry ovgroup:insert(retrybutt) -- mainbutt=display.newImage("images/menu.png",140,250) -- mainbutt.id=mainmenu -- ovgroup:insert(mainbutt) --mainbutt:addEventListener("touch",init) retrybutt:addEventListener("touch",init) end relevel\_a() return scene
It would be great if there is a mechanism to make transitions between display groups