You basically have a scope problem. It’s really hard to spot because your code isn’t indented very well. You can’t tell where functions begin and end, where if statements begin and in, etc.
You declare player1 local inside of scene:create(), but your touch handler is outside of the scene:create() function and at that point, player1 is unknown.
--Hide the status bar. display.setStatusBar( display.HiddenStatusBar) function onCollision( event ) if ( event.phase == "began" ) then composer.gotoScene( "menu" ) end end -- Actual Scene function scene:create( event ) local sceneGroup = self.view --Set the background color to white local background = display.newRect( 0, 0, display.contentWidth, display.contentHeight ) background:setFillColor( 1 ) background:setFillColor( 255, 255, 255 ) background.x = display.contentCenterX background.y = display.contentCenterY sceneGroup:insert( background ) --Add as score label local score = 0 local scoreLabel = display.newText( score, 0,0, native.systemFontBold, 24) scoreLabel.x = display.viewableContentWidth / 1.5 scoreLabel.y = display.viewableContentHeight / 15 scoreLabel :setTextColor(0,0,0) ----Create Player local player1 = display.newRect( 0, 0, 20, 20 ) player1:setFillColor( 0 ) player1:setStrokeColor( 1, 0, 0 ) player1.x = display.viewableContentWidth / 2 player1.y = display.viewableContentHeight / 2 local function animate( event ) player1.rotation = player1.rotation + 20 end Runtime:addEventListener( "enterFrame", animate ); end ---Touch Event function player1:touch( event ) if event.phase == "began" then self.markX = self.x self.markY = self.y elseif event.phase == "moved" then local x = (event.x - event.xStart) + self.markX local y = (event.y - event.yStart) + self.markY self.x,self.y = x, y ---moves object based on cal end return true end player1:addEventListener("touch", player1) -------------Start function scene: show (event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" add end and this should b bottom function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then Runtime:removeEventListener("collision", onCollision) Runtime:removeEventListener("collision", onCollision) elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) physics.setGravity( 0, 0 ) --------------------------------------------------------------------------------- return scene