score problem in game

hey everybody

in my game, i am creating a collision event, were as when you collide with the object, you get 100 points, but there is a problem with that in my game, here it is. its is either coming up with an error saying "attempt to index upvalue enemyBalloon or “trying to compare number with nil”.  can someone please help me, im really urgent. thanks!

Hazza

display.setStatusBar(display.HiddenStatusBar) local physics = require "physics" physics.start();physics.setGravity(0,2.7) local ox, oy = math.abs(display.screenOriginX) + 25, math.abs(display.screenOriginY) local cw, ch = display.contentWidth, display.contentHeight local stage = display.getCurrentStage() physics.setDrawMode("normal") local &nbsp;foreGround = display.newGroup() local Balloons = display.newGroup() Balloons.isVisible = true local scoreLabel local scoreObj local score = 0 --------------------------------------------------------------------- --FOREGROUND OBJECTS -------------------------------------------------------------------- local background = display.newImage(foreGround,"background.jpg") background.x = 0 local ground = display.newImage(foreGround,"floor.png") physics.addBody(ground,"static") ground.x = 10 ground.y = 480 ground.myName = "removeObject" local turret = display.newImageRect(foreGround,"BalloonTurret.png",134,134) turret:setFillColor(45, 255, 215) turret.x = 160 turret.y = 420 local ox, oy = math.abs(display.screenOriginX), math.abs(display.screenOriginY) local cw, ch = display.contentWidth, display.contentHeight local wallL = display.newRect( -ox, -oy,1.5, ch+oy+oy ) wallL.isVisible = false physics.addBody(wallL, "static", { bounce=0.6, friction=1.0 } ) wallL.type = "notSticky" local wallR = display.newRect( cw-1.5+ox, -oy, 1.5, ch+oy+oy ) &nbsp;&nbsp; wallR.isVisible = false &nbsp; physics.addBody(wallR, "static", { bounce=0.6, friction=1.0 } ) wallR.type = "notSticky" local wallT = display.newRect( -ox, -oy, cw+ox+ox, 1.5 ) wallT.isVisible = false physics.addBody(wallT, "static", { bounce=0.6, friction=1.0 } ) wallT.isSensor = true wallT.y = -74 wallT.myName = "removeObject" ------------------------------------------------------------- ------------------------------------------------------------- local projFiring = false local proj local enemyBalloon local scaleFactor = 1.0 local physicsData = (require "Balloon").physicsData(1.0) --display.newRoundedRect( left, top, width, height, cornerRadius ) local myRoundedRect local idx = 0 for xVal = 1,9 do idx = idx + 1 &nbsp;myRoundedRect = display.newRoundedRect(0, 0, 20, 10, 3) &nbsp; myRoundedRect.x = (xVal \* 34) -10 &nbsp; myRoundedRect.y = 60 &nbsp; &nbsp;myRoundedRect.alpha = 0.4 myRoundedRect.strokeWidth = 3 myRoundedRect:setFillColor(140, 140, 140) myRoundedRect:setStrokeColor(220, 255, 216) end local function addToScore(num) score = score + num scoreObj.text = score scoreObj:setReferencePoint(display.CenterLeftReferencePoint) if enemyBalloon.y \> myRoundedRect.y then score = 200 elseif enemyBalloon.y \< myRoundedRect.y then score = 100 end end scoreLabel = display.newText("Score: ",0,0,native.systemFont,18) --scoreLabel:setFillColor(246, 255, 218) scoreLabel.x = 250 scoreLabel.y = &nbsp;10 scoreObj = display.newText(tostring(score),0,0,native.systemFont,18) scoreObj.x = scoreLabel.x + 32 scoreObj.y = scoreLabel.y local t --collision handler local function projCollide( self,event ) &nbsp;&nbsp;&nbsp;&nbsp;if ( event.phase == "began" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--get world coordinates of projectile for joint reference&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--self:removeEventListener( "collision", self ) ; self.collision = nil &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--delay function to resolve collision &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local function resolveColl( timerRef ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( timerRef.source.action == "makeJoint" ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local weldJoint = physics.newJoint( "weld", self, event.other, self.x, self.y ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--check if velocity of projectile is sufficient to "stick" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local vx,vy = self:getLinearVelocity() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local dirVel = math.sqrt( (vx\*vx)+(vy\*vy) ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( dirVel \> 10 ) &nbsp; then &nbsp;--if sufficient, stop velocity and trigger joint creation &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self:setLinearVelocity( 0,0 ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t = timer.performWithDelay( 10, resolveColl, 1 ) ; t.action = "makeJoint" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addToScore(100) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;--if not sufficient, "break" projectile and create new &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t = timer.performWithDelay( 10, resolveColl, 1 ) ; t.action = "none" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (event.other.type == "notSticky") &nbsp;then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --t = timer.performWithDelay(10,resolveColl,1) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.action = "none" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elseif (event.other.myName == "removeObject") then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self:removeSelf();t.action = "none";self = nil &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print("i got removed") &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;end end local function newProj() &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;proj = display.newImage(Balloons,"Balloon.png"); proj.x = turret.x ; proj.y = turret.y - 20 &nbsp;&nbsp;&nbsp;&nbsp;physics.addBody( proj, "dynamic",physicsData:get("balloon") ) &nbsp;&nbsp;&nbsp;&nbsp;proj.gravityScale = -5 &nbsp;&nbsp;&nbsp;&nbsp;projFiring = false &nbsp;&nbsp;&nbsp;&nbsp;proj.isBullet = true &nbsp;&nbsp;&nbsp;&nbsp;proj.isBodyActive = false &nbsp;&nbsp;&nbsp;&nbsp;proj.isVisible = false &nbsp;&nbsp;&nbsp;&nbsp; end local function spawnEnemy() &nbsp;enemyBalloon = display.newImage(Balloons,"Balloon.png") physics.addBody(enemyBalloon,"dynamic", physicsData:get("balloon") ) enemyBalloon.x = math.random(0,310) enemyBalloon.y = -55 enemyBalloon:setFillColor( 214, 0, 19 ) enemyBalloon:applyTorque( 50 ) enemyBalloon.type = "notSticky" enemyBalloon.collision = projCollide enemyBalloon:addEventListener("collision",enemyBalloon) return enemyBalloon end local function touchAction(event) &nbsp;&nbsp;&nbsp;&nbsp;if ( event.phase == "began" and projFiring == false ) then &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;projFiring = true &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proj.isBodyActive = true &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proj.isVisible = true &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local px,py = event.x-proj.x, event.y-proj.y &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proj:applyLinearImpulse( px/8, py/8, proj.x, proj.y ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proj:applyTorque( 50 ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proj.gravityScale = -5 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;proj.collision = projCollide ; &nbsp; proj:addEventListener( "collision", proj ) &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if (projFiring == true) then &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newProj() &nbsp;&nbsp;&nbsp;&nbsp;end end newProj() stage:addEventListener( "touch", touchAction ) local spawnTmr local spawnTime = 5000 local difficultyLevels = 4 --local spawnTimer = timer.performWithDelay(5000,spawnEnemy, 0 )---- THIS IS AN &nbsp;INFINITE LOOP HARRY ,U MUST YOU'SE THIS A LOT local function increaseDifficulty() &nbsp; &nbsp; &nbsp; &nbsp; if spawnTmr ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timer.cancel(spawnTmr) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spawnTmr = nil &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp;spawnTime = spawnTime - 1000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- just to be safe, set this to whatever spawn rate would be the &nbsp; &nbsp; &nbsp; &nbsp;-- fastest, so game never spawns to fast &nbsp; &nbsp; &nbsp; &nbsp;if spawnTime \< 1000 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;spawnTime = 3000 &nbsp; &nbsp; &nbsp; &nbsp;end &nbsp; &nbsp; &nbsp; &nbsp;-- spawn at this rate until this timer is canceled&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;spawnTmr = &nbsp;timer.performWithDelay(spawnTime, spawnEnemy, 0) &nbsp; &nbsp; end &nbsp; &nbsp; -- this timer loops only till spawning at most difficult speed is reached &nbsp; &nbsp; local difficultyTmr = &nbsp;timer.performWithDelay(5000, increaseDifficulty,difficultyLevels ) &nbsp;