Your first problem is that you're not updating your matrix after randomizing it:
rem Randomize the matrix
randomize matrix 1,125
update matrix 1
X#=5000
Z#=5000
Should show the matrix randomized now (side note: 125 isn't very much in your scale (barely noticable) so you might want to randomize it more).
Finally, you've written 2 limitations to your roaming space, look at your code:
Rem Control input for camera
If Upkey()=1
XTest# = Newxvalue(X#,CameraAngleY#,40)
ZTest# = Newzvalue(Z#,CameraAngleY#,40)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif
This particular line:
"If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000"
is preventing you from going past the x and z axes as well as preventing you going past 10000 away from the Z and X. Hence, your problem. I'm guessing you think the edge of the matrix is created on 0,0 but this is not the case, the matrix's center is 0,0 and that's why you can't get passed. Simply change it to something like this:
Rem Control input for camera
If Upkey()=1
XTest# = Newxvalue(X#,CameraAngleY#,40)
ZTest# = Newzvalue(Z#,CameraAngleY#,40)
If XTest#>-50000 and XTest#<50000 and ZTest#>-50000 and ZTest#<50000
X#=XTest#
Z#=ZTest#
Endif
Endif
And Voila! Also do the same for walking backwards, left, and right and it should work. Note: I got the 50,000 value from the size you created your matrix (100,000 / 2 because it's evenly distributed on both sides of the axis), if you ever change the size of your matrix then you will need to change it again. Likewise if you add another matrix then you'll need to make it larger yet again.
"Computers are useless they can only give you answers."