setLinearVelocity return error when it set on collision event

Hi all,

I’m trying to create splatter stars when the ball collided with the wall and when I set the star linearVelocity it return error "attempt to call method ‘setLiniearVelocity’ (a nil value), below is the code that I wrote:

[lua]

function onWallCollision(self, event)

  – Remove the ball that collided with the wall

  event.other:removeSelf()

  

  --Create splatter stars when ball collided with the wall

  for  i = 1, 50 do

    local imgsize = math.random(1, 20)

    local starId =  math.random(1, 5)

    local splatterStar = display.newImageRect(“images/star” … starId … “.png” ,imgsize, imgsize)

    splatterStar.x = event.x

    splatterStar.y = event.y

    physics.addBody(splatterStar, “dynamic”, starProp)

    local xVelocity = math.random(-150, 150)

    local yVelocity = math.random(-150, 150)

    splatterStar:setLinearVelocity(xVelocity, yVelocity)

    transition.to(splatterStar, {time = 3000, delay = 3000, width = 0, height = 0, alpha = 0, onComplete = function(event) splatterStar:removeSelf() end})

  end

end

[/lua]

Is it not possible to set LiniearVelocity on collision event? is there any workaround for this issue?

Many Thanks.