Well think about the pick, if its not on the cube then no pick results.
This can be seen in this slight alteration to your code:
'Use the Leadwerks Engine module as our base
Framework leadwerks.engine
'Create an OpenGL graphics window
Graphics 800, 600
'Allows the engine to find files and load files from zip packages
RegisterAbstractPath AppDir
'Create a world
If Not CreateWorld() RuntimeError "Failed to create world."
'Create a camera
cam:TCamera = CreateCamera()
CameraClearColor(cam, Vec4(0, 0, 1, 1))
MoveEntity cam, Vec3(0, 20, - 35)
'create a ligt
light:TLight = CreateDirectionalLight()
RotateEntity(light, Vec3(65, 45, 0))
'Create a render Buffer
buffer:TBuffer = CreateBuffer(800, 600, BUFFER_COLOR | BUFFER_DEPTH | BUFFER_NORMAL)
'create a mesh
cube:TMesh = CreateCube()
ScaleEntity(cube,Vec3(2,2,2))
ground:TMesh = CreateCube()
ScaleEntity(ground,Vec3(40,0.01,40))
PositionEntity(ground,Vec3(0,-2,0))
Local pick:TPick
'create materials
selectionmaterial:TMaterial = CreateMaterial()
SetMaterialColor(selectionmaterial, Vec4(1, 0, 0, 1))
pointentity cam , cube
'Main loop
Global loctite:Int = 1
While Not KeyHit(KEY_ESCAPE)
If MouseDown(1)
PaintEntity(cube, 0)
PaintEntity(ground, 0)
pick = CameraPick(cam, Vec3(MouseX(), MouseY(), 1000))
If pick
PaintEntity(pick.entity, selectionmaterial)
positionentity (pick.entity , vec3(pick.x,0,pick.z))
End If
End If
'Update timing, physics, and other miscellaneous updates
UpdateWorld
'Draw the world
SetBuffer(buffer)
RenderWorld
'render lighting
SetBuffer(BackBuffer())
RenderLights(buffer)
'Swap the graphics buffers so we can see what we drew
Flip
Wend