| Eh, well I'm not entirely sure where the error is occurring... So here's the whole code. I apologize for how messy it is.. 
 
  Include "DPS\System\DevilParticleSystem.bb"
Graphics3D 800, 600, 0, 1					;3D graphics at a resolution of 800x600
SetBuffer BackBuffer()						;do all drawing to the back drawing buffer
Const PLAYER_COL= 1                         ;Set collisions
Const LEVEL_COL = 2
Const ENEMY_COL = 3
Const BULLET_COL= 4
Const WEAPON_COL= 5
Const ITEM_COL=6
Const ITEM2_COL=7
Const DEATH_COL=8
Type bullettype				;set up the bullet type
  Field entityhandle		;create a field to contain the handle of the bullets mesh
End Type
Type badguytype				;set up the badguy type
  Field entityhandle		;will contain the handle of the badguys mesh
  Field state				;will contain the state that the badguy is currently in
  Field return_waypoint
  Field speed#
End Type
Type weapontype             ;Set up weapon type
 Field entityhandle
End Type
Type blood				;Set up particle type
	Field mesh		
	Field alpha#
	Field speed_x#
	Field speed_y#
	Field speed_z#
	Field fade_speed#
End Type
Global spark = LoadSprite("Particle-038.png") ;Blood effect
	ScaleEntity spark, .25,.25,.25
	
	HideEntity spark
Global player_hp = 10			;give the player 10 hit points
Global player_alive = 1			;player is indeed alive
Global waypoint = CreateSphere()
	ScaleEntity waypoint, .0005,.0005,.0005 ; too small to see
	EntityColor waypoint, 0,200,0
	HideEntity waypoint
	
clouds = CreatePlane()
cloud_tex=LoadTexture("cloud_2.bmp")
ScaleTexture cloud_tex,20,20
EntityTexture clouds,cloud_tex
RotateEntity clouds,0,0,180                   ;rotate 180 degrees to be visible from the ground
PositionEntity clouds,0,20,0                  ;place it in the sky
EntityAlpha clouds,.9
Deathplane = CreatePlane()
EntityType deathplane,DEATH_COL
PositionEntity deathplane,0,-70,0
EntityAlpha deathplane,1
tex=LoadTexture("ground.bmp") ;Various textures for temporary backgrounds :p
ScaleTexture tex,.05,.05
tex2=LoadTexture("sky.bmp")
light = CreateLight()						;Create a light to see
RotateEntity light, 30, 30, 0				;angle the light
Global player = CreatePivot()				;A simple pivot is all we need to represent the player
Global camera = CreateCamera(player)		;create the camera and attach it to the player
CameraRange camera, .01, 250				;set the camera range to something reasonable
CameraClsColor camera,0,0,0
;==========================================================================================
;TEMPLATES AND EMITTERS
;==========================================================================================
InitParticles(Camera)
template = CreateTemplate()
SetTemplateEmitterBlend(template, 1)
SetTemplateInterval(template, 5)
SetTemplateEmitterLifeTime(template, -1)
SetTemplateParticleLifeTime(template, 30, 45)
SetTemplateTexture(template, "DPS\particle collection\normal\particle-016.png", 2, 1)
SetTemplateOffset(template, -.3, .3, -.3, .3, -.3, .3)
SetTemplateVelocity(template, -.04, .04, .1, .2, -.04, .04)
SetTemplateAlphaVel(template, True)
SetTemplateSize(template, 3, 3, .5, 1.5)
SetTemplateSizeVel(template, .01, 1.01)
SetTemplateBrightness(template,1)
emitter = CreatePivot() ;The emitter can also be a mesh(don't have to be a pivot!)
EntityType emitter,ITEM2_COL
SetEmitter(emitter, template) ;Sets the template which was created to this emitter pivot
PositionEntity emitter,0,1,20
template2 = CreateTemplate()
SetTemplateEmitterBlend(template2, 3)
SetTemplateInterval(template2, 1)
SetTemplateParticlesPerInterval(template2, 10)
SetTemplateEmitterLifeTime(template2, -1)
SetTemplateParticleLifeTime(template2, 20, 20)
SetTemplateTexture(template2, "DPS\particle collection\normal\particle-025.png", 3)
SetTemplateOffset(template2, -10, 10, 4.5, 5.5, -5, 5)
SetTemplateVelocity(template2, .1, .1, -.03, -.03, 0, 0)
SetTemplateGravity(template2, .1)
SetTemplateSize(template2, -.03, -.3)
SetTemplateFixAngles(template2, 0, -1)
emitter2 = CreatePivot(camera) ;The emitter can also be a mesh(don't have to be a pivot!)
SetEmitter(emitter2, template2) ;Sets the template which was created to this emitter pivot
PositionEntity emitter2,0,10,10
template3 = CreateTemplate()
SetTemplateEmitterBlend(template3, 1)
SetTemplateInterval(template3, 1)
SetTemplateParticlesPerInterval(template3, 1)
SetTemplateEmitterLifeTime(template3, -1)
SetTemplateParticleLifeTime(template3, 20, 30)
SetTemplateTexture(template3, "WaterHit.png", 3, 3)
SetTemplateOffset(template3, -2.5, 2.5, 1, 1, -2.5, 2.5)
SetTemplateAlphaVel(template3, True)
SetTemplateSize(template3, .002, .002, .8, 1.3)
SetTemplateSizeVel(template3, .03, 1)
SetTemplateFixAngles(template3, 90, -1)
emitter3 = CreateCube()
HideEntity emitter3
setemitter(emitter3, template3)
PositionEntity emitter3,0,-1,6
;STAGE MESHES /\/\/\/\
level = LoadMesh("stage.b3d"):ScaleEntity level,0.5,0.5,0.5:MoveEntity level,0,34,0			;load in the level mesh
EntityTexture level,tex
;=======================================================================================
;SOUNDS AND SFX
;=======================================================================================
microphone=CreateListener(camera)                ;Creates listener and attaches it to the camera
sound=Load3DSound("real hit.wav")                ;SFX for firing the gun
sound2=Load3DSound("Gun_Reload.wav")             ;SFX for reloading
Soundtrack=Load3DSound("Tallon Overworld.mp3")     ;Backgound music
empty=Load3DSound("empty.wav")
jet=Load3DSound("jetpack.wav")
Global deathsfx=Load3DSound("death.mp3")
Snd_Water = LoadSound("Fountain.wav")
SoundVolume snd_water,.3
LoopSound Snd_Water
EmitSound Snd_Water,camera
                     ;play background music
SoundVolume soundtrack,2
LoopSound soundtrack
EmitSound(soundtrack, camera)
CameraFogRange camera,1,70                        ;Set camera fog mode (what's this doing here? XD)
CameraFogMode camera,1
CameraFogColor camera,0,0,0
;Aditional meshes, animmeshes and sprites
weapon1 = LoadAnimMesh("pistolhand.b3d", camera)			;load in the weapon mesh and attach it to the camera
RotateMesh weapon1, -10, -75, 0:ScaleEntity weapon1, .005, .005, .005:TranslateEntity weapon1,-.04,.04,.10
bulletmesh = LoadMesh("bullet.b3d")				;load in a bullet mesh (this will be a template mesh)
c = LoadSprite("crosshair.png", 2, camera)      ;crosshair sprite
PositionEntity c, 0, 0, 15
EntityOrder c, -1
 b = LoadSprite("backpack2.png")
EntityType b, ITEM_COL     
EntityRadius b, 1.5, .95                ;Backpack sprite for item
PositionEntity b, 0, 1, 0
EntityOrder b , -1
bicon = LoadSprite("backpack2.png",2,camera)    ;Backpack sprite for HUD
PositionEntity bicon, -19.3, 8, 20
EntityOrder bicon , -1
HideEntity bicon
Global Pistolmesh = LoadMesh("pistol.b3d")             ;Collectable gun mesh
EntityType pistolmesh, WEAPON_COL
EntityRadius pistolmesh, 1.5, .95
ScaleEntity pistolmesh, .05, .05, .05
PositionEntity pistolmesh, 10,0,0
;ANIM SEQUENCES
ExtractAnimSeq weapon1,0,1           ;Extract sequences for gun movement animation
ExtractAnimSeq weapon1,2,11
ExtractAnimSeq weapon1,39,69
ExtractAnimSeq weapon1,70,80
ExtractAnimSeq weapon1,81,90
RotateMesh bulletmesh,0,-5,0:ScaleEntity bulletmesh,.1,.1,.1:EntityColor bulletmesh, 50, 50, 50
EntityType bulletmesh, BULLET_COL				;set up collision type for the bullet
EntityRadius bulletmesh, .01					;set up collision radius for the bullet
badguymesh = LoadAnimMesh("Robot.b3d")				;load in badguy mesh (this will also be a template mesh)
RotateEntity badguymesh,0,0,0
ScaleEntity badguymesh,.15,.15,.15;.6 wide, 1.9 tall, .25 thick
EntityType badguymesh, ENEMY_COL				;set up collision type for the badguy
EntityRadius badguymesh, .3, .95	 			;set up collision radius for the badguy (1.9 meters tall, .6 meters wide)
HideEntity bulletmesh						;hide the template meshes since they are not actual objects
HideEntity badguymesh						;this will also exclude them from collisions
ExtractAnimSeq badguymesh,0,39
;/\/\/\/\/\ MAKING ENEMIES!
For iter = 1 To 20						;create some badguys from the template badguy mesh
  badguy.badguytype = New badguytype				;create a new badguy
  badguy\entityhandle = CopyEntity(badguymesh)			;give him a mesh
  badguy\state = 1 :Animate badguy\entityhandle,2,.3,0,5 ;1=Guard 2=drop new way point 3=follow 4=Attack 5=return to waypoint 6=dead x.x
  badguy\speed = .15
Next
MoveEntity camera, 0, .9, 0					;move camera up to height of players head (also moves weapon)
MoveEntity weapon1, .16, -.17,- .01				;move weapon to bottom right of camera
MoveEntity player, 20, 1, -20					;move the player to the starting position
For badguy = Each badguytype					;iterate through all of the badguys
  PositionEntity badguy\entityhandle, Rnd(100)-50, .95, Rnd(100)-50	;move the badguy to a random starting position
Next
 
EntityType player, PLAYER_COL					;set up collision type for the player
EntityRadius player, .3, .95					;set up the players collision radius (1.9 meters tall, .6 meters wide)
EntityType level, LEVEL_COL					;set up collision type for the level
Collisions PLAYER_COL, LEVEL_COL, 2, 2				;player to level
Collisions PLAYER_COL, ENEMY_COL, 1, 2				;player to badguy
Collisions ENEMY_COL, LEVEL_COL, 2, 2				;badguy to level
Collisions BULLET_COL, LEVEL_COL, 2, 1				;bullet to level
Collisions BULLET_COL, ENEMY_COL, 2, 1				;bullet to badguy
Collisions PLAYER_COL, WEAPON_COL,1,2              ;weapon to player
Collisions PLAYER_COL, ITEM_COL,1,2 
Collisions PLAYER_COL, ITEM2_COL,1,2 
Collisions ENEMY_COL, ENEMY_COL, 1, 2
Collisions PLAYER_COL, DEATH_COL,2,1
ammo=10 ;AMMO REMAINING
clip=50 ;CLIP REMAINING
parachute=False ;PARACHUTE DEACTIVATED
ptime=1000 ;PARA TIME 19secs...ish
Pon=False   ;Switch for gravchute : off
Jon=False   ;Switch for jetpack   : off
Jtime=500  ;Fuel remaining
ammodiff=10 ;Controler for reloading, DO NOT TOUCH!
While Not KeyHit(1)  					;ESC key MAIN LOOP/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ <--!!!!!!!!!!!!!!!!
TranslateEntity clouds,0.05,0,0.05 ; make clouds roll across the sky...
UpdateParticles()
	run_enemies()
	run_particles()
	check_hp()
If player_alive=1
  wkey = KeyDown(17)			;collect user input, this is messy...
  skey = KeyDown(31)			
  akey = KeyDown(30)			
  dkey = KeyDown(32)			
  mouse1 = MouseHit(1)			
  space = KeyHit(57)
EndIf
If (player_alive =0) And (i<180) 
i=i+1  
TurnEntity player,0,-2,-2
EndIf
If (player_alive =0) And (j#<255)
j#=j# +.5
CameraFogColor camera,j#,0,0
CameraClsColor camera,j#,0,0
CameraFogRange camera,-j#,5
EndIf
If player_alive=1
 ; mouse1 = MouseDown(1) ;Toggle for Rapid-fire mode
  If wkey Then MoveEntity player, 0, 0, .2			   ;Forward - w key
  If skey Then MoveEntity player, 0, 0, -.1			   ;Back    - s key
  If akey Then MoveEntity player, -.1, 0, 0			   ;Left    - a key
  If dkey Then MoveEntity player, .1, 0, 0			   ;Right   - d key
  If space Then EmitSound(sound2,camera)               ;Clickclick...
  If (space) And (clip=0) Then EmitSound(empty,camera) ;empty sound if reload fails
If (space) And (clip>0) Then ammodiff=ammodiff-ammo :ammo=ammo+ammodiff :clip=clip-ammodiff :ammodiff=10 
If clip > 100 Then clip = 100
 
  If KeyHit(17) Then Animate weapon1,2,-1,3,5         ;animate moving forwards
  If Not (wkey) Or (akey) Or (dkey) Or (MouseDown(1)) Then Animate weapon1,0,-1,3,10 ;stop animating if not moving or firing weapon
  If KeyHit(30) Then Animate weapon1,3,1,4,5          ;gun turns left...
  If KeyHit(32) Then Animate weapon1,3,1,5,5          ;gun turns right...
 
  TurnEntity player, 0, -MouseXSpeed()/5.0, 0			;rotate player Pivot according to mouse X movement
  TurnEntity camera, MouseYSpeed()/5.0, 0, 0			;rotate camera up/down according to mouse Y movement
  If EntityPitch(camera) < -45					;don't allow camera to look below -45 degrees
    RotateEntity camera, -45, EntityYaw(camera), EntityRoll(camera)
  EndIf 
  If EntityPitch(camera) > 45					;don't allow camera to look above 45 degrees
    RotateEntity camera, 45, EntityYaw(camera), EntityRoll(camera)
  EndIf
EndIf
  MoveMouse GraphicsWidth()/2, GraphicsHeight()/2		;reset mouse position to middle of screen
;PHYSICS/\/\/\/\ >.<
  
  If parachute = False Then TranslateEntity player, 0, -.4, 0				;gravity
 
;parachute test/\/\/\
 If (KeyHit(18)) And (Pon=True) Then parachute=True
 If parachute=True Then TranslateEntity player,0,-.05,0:ptime=ptime-1
 If ptime=<0 Then parachute=False:Pon=False
 If pon = True Then ShowEntity bicon
 If pon = False Then HideEntity bicon
;jetpack test/\/\/\
If (MouseDown(2)) And (Jon=True) Then TranslateEntity player,0,0.5,0:Jtime=Jtime-1
If (MouseHit(2)) And (Jon=True) Then EmitSound jet,camera
If Jtime=<0 Then Jon=False
If player_alive=0 Then jon=False
	
;AMMO/BULLET CONTROL/\/\/\/\
If ammo > 0 Then ;check if ammo is depleted
  If mouse1 Then							;check if left mouse button was pressed
Animate weapon1,3,1,2,5                ;animate firing weapon
ammo=ammo-1
EmitSound(sound,camera)
    bullet.bullettype = New bullettype				;create a bullet
    bullet\entityhandle = CopyEntity(bulletmesh)		;create the bullet mesh
    PositionEntity bullet\entityhandle, EntityX(weapon1, 1), EntityY(weapon1, 1), EntityZ(weapon1, 1)	;place the bullet at the guns position
    RotateEntity bullet\entityhandle, EntityPitch(weapon1, 1), EntityYaw(weapon1, 1), EntityRoll(weapon1, 1);orientate the bullet with the gun
    ResetEntity bullet\entityhandle				;otherwise bullet could hit enemy while moving from 0,0,0 to current position
  EndIf
  For thisbullet.bullettype = Each bullettype			;iterate through all of the bullets
    MoveEntity thisbullet\entityhandle, 0, 0, 2			;move the bullet forward along the bullets Z axis !
    If Abs(EntityX(thisbullet\entityhandle, 1)) > 10000		;check if the bullet is way out of bounds
      FreeEntity thisbullet\entityhandle			;delete the bullet mesh
      Delete thisbullet						;delete the bullet
    ElseIf Abs(EntityY(thisbullet\entityhandle, 1)) > 10000	;check if the bullet is way out of bounds
      FreeEntity thisbullet\entityhandle			;delete the bullet mesh
      Delete thisbullet						;delete the bullet
    ElseIf Abs(EntityZ(thisbullet\entityhandle, 1)) > 10000	;check if the bullet is way out of bounds
      FreeEntity thisbullet\entityhandle			;delete the bullet mesh
      Delete thisbullet						;delete the bullet
    EndIf
  Next
EndIf
;Collectable gun control? (WORKING)
If EntityCollided(player,WEAPON_COL) Then clip = clip + 50 : HideEntity pistolmesh : EmitSound empty,camera
If EntityCollided(player,ITEM_COL) Then pon = True : HideEntity b : EmitSound empty,camera 
If EntityCollided(player,ITEM2_COL) Then jon = True :  EmitSound empty,camera : Jtime = 500 
;If EntityCollided(player,DEATH_COL)Then player_alive = 0
 
  UpdateWorld							;figures out collisions, yada yada yada...
  For thisbullet = Each bullettype				;iterate through all of the bullets
    If CountCollisions(thisbullet\entityhandle) > 0		;check if bullet collided with something
      enemyhit = EntityCollided(thisbullet\entityhandle, 3)	;note which enemy bullet collided with (if any)
      If enemyhit > 0 Then KillBadGuy(enemyhit)			;enemyhit contains entity handle of enemy that was hit
      FreeEntity thisbullet\entityhandle			;delete the bullet mesh
      Delete thisbullet						;delete the bullet
    EndIf
  Next
  
  RenderWorld							;draws the 3d scene
Text 0,0,"ammo: "                       ;Text to screen rendering
Text 0,20,ammo
Text 0,30,"clip: "
Text 0,50,clip
Text 300,0,"HP: ":Text 330,0,player_hp
If parachute=True Then Text 0,70,"Gravchute on "
If parachute=True Then Text 0,85,ptime
If Jon = True Then Text 0,100,"Jetpack: " +Jtime
If player_alive = 0
		Text 350,290,"You are DEAD!"
EndIf
  Flip		;displays the scene to the screen
Wend	 ;loop until the ESC key is pressed
FreeParticles()
End
;EndIf
;FUNCTION RUN_ENEMIES   
Function run_enemies()
	For badguy.badguytype = Each badguytype	;for each enemy
	
		;regardless of case, the distance to the player must be known, so we'll check it here
		Local dist# = EntityDistance(badguy\entityhandle,player)
		
			Select badguy\state			;select it's status
				
				Case 1 ;ON GUARD
				    
					;EntityColor badguy\entityhandle, 200,200,0
					If dist# <= 10		;if the distance is less than 10 or equal to it
						If player_alive = 1
							badguy\state = 2:Animate badguy\entityhandle,2,1,0,5	;switch to state 2
						End If
					End If
				
				Case 2 ;DROP NEW WAYPOINT
					Local x# = EntityX(badguy\entityhandle)	;grab the enemies' coordinates
					Local y# = EntityY(badguy\entityhandle)
					Local z# = EntityZ(badguy\entityhandle)
					
						;place the waypoint at the location
						badguy\return_waypoint = CopyEntity(waypoint)
						PositionEntity badguy\return_waypoint,x#,y#,z#
						
						badguy\state = 3	;then switch to case 3, which is pursue
						cry=Load3DSound("porycry2.mp3")
					EmitSound cry,camera
				
				Case 3 ;PURSUE THE PLAYER
					;EntityColor badguy\entityhandle, 200,0,0	;red
					
					If dist# < 1	;then attack!
						badguy\state = 4;change to attack
							
						Exit 		;exit the loop
					End If 
					
					If dist# < 12	;first, check to see if we're 12 units away or less....
						PointEntity badguy\entityhandle, player :TurnEntity badguy\entityhandle,0,180,0		;point enemy at the player
						MoveEntity badguy\entityhandle, 0,0,-badguy\speed	;then make the enemy move in the pointed direction
					Else
						badguy\state = 5	;set to status 5, which is return to waypoint
					End If 	
		
				Case 4 ;ATTACK
					player_hp = player_hp - 1	;take 1 hp from the player
					badguy\state = 5				;now return to the waypoint
					Local s_x# = EntityX(player)
					Local s_y# = EntityY(player)
					Local s_z# = EntityZ(player)
					Local num = Rand(3,8)
						create_particles(num,s_x,s_y,s_z)
						
				
				Case 5 ;RETURN TO WAYPOINT
					;EntityColor badguy\entityhandle, 200,0,200
					Local dist_home# = EntityDistance(badguy\entityhandle,badguy\return_waypoint)	;get the distance home
						If dist_home# > .2							;If we're further than .2 away...
							PointEntity badguy\entityhandle, badguy\return_waypoint:TurnEntity badguy\entityhandle,0,180,0	;point at home waypoint
							MoveEntity badguy\entityhandle, 0,0,-badguy\speed			;move them forward
						Else If dist_home# <= .2
							FreeEntity badguy\return_waypoint			;get rid of the waypoint mesh
							badguy\state = 1:Animate badguy\entityhandle,2,.3,0,5							;and return to idle again
						End If
						
			
				 
				   
				
				
			
			End Select
	Next
End Function
Function check_hp() ;CONTROLS HP/\/\/\/\
If player_hp <= 0
	player_hp = 0
	If player_alive = 1
	Local s_x# = EntityX(player)
	Local s_y# = EntityY(player)
	Local s_z# = EntityZ(player)
	Local num = Rand(15)
		;effects? maybe?
		
	player_alive = 0
	
If player_alive = 0 
 MoveEntity player,0,0,0
 SoundVolume deathsfx,2
 EmitSound(deathsfx,camera)
EndIf
	End If
	
End If 
End Function
Function KillBadGuy(enemyhit) ;DIE!!
sound4=Load3DSound("Porycry.wav")  
EmitSound(sound4,camera)
  For thisbadguy.badguytype = Each badguytype			;iterate through all of the badguys
    If enemyhit = thisbadguy\entityhandle			;check if the enemy hit = this badguy
      If thisbadguy\state <> 6					;check if badguy is alive
        thisbadguy\state = 6 :Animate thisbadguy\entityhandle,0,0,0,5	;make him dead
        EntityType thisbadguy\entityhandle, 0			;turn off collisions for this badguy
        RotateEntity thisbadguy\entityhandle, 90, 0, 0		;make him horizontal
        TranslateEntity thisbadguy\entityhandle, 0, -.9, 0	;set him on the ground
        Exit							;exits the badguy For-Next loop (no need to check rest of badguys)
      EndIf
    EndIf
  Next
End Function
Function run_particles()          ;CONTROLS BLOOD EFFECTS\/\/\/\/\
For p.blood = Each blood
	p\alpha = p\alpha - p\fade_speed	;take fade speed from alpha
	EntityAlpha p\mesh, p\alpha			;set alpha to p\alpha
		If p\alpha <= 0					;if alpha is <= 0
			FreeEntity p\mesh			;free it
			Delete p				
			Exit						;exit the loop
		Else
			p\speed_y = p\speed_y - .01							;subtract from y speed
			MoveEntity p\mesh, p\speed_x, p\speed_y,p\speed_z	;move the particle
		End If
		
		
Next 
End Function 
Function create_particles(num,x#,y#,z#) ;CREATES BLOOD EFFECTS\/\/\/\/\/\
	For s = 1 To 15;num
		p.blood = New blood
		p\mesh = CopyEntity(spark)
		p\speed_x# = Rnd(-.2,.2)
		p\speed_y# = Rnd(.3)
		p\speed_z# = Rnd(-.2,.2)
		p\alpha = 1
		p\fade_speed# = Rnd(.1)
		PositionEntity p\mesh, x,y,z
	Next
End Function
 
 |