sound.play Lua Errors

Hello everyone. I’m not much of a coder and I’ve suddenly been getting errors in one of my addons. The line of code is:

sound.Play( table.Random(bloodysounds), vPos, 75, 165, 100 )

And the console is telling me: bad key to string index (number expected, got string). I’m not sure what went wrong or what has been updated. Could someone help me out? Thanks.

This isn’t exactly helpful, can you post more of the code? Specifically where the variable bloodysounds is defined.

Sure thing. Here’s the bloodysounds:


local bloodysounds = {}
bloodysounds[1] = "physics/flesh/flesh_squishy_impact_hard1.wav"
bloodysounds[2] = "physics/flesh/flesh_squishy_impact_hard2.wav"
bloodysounds[3] = "physics/flesh/flesh_squishy_impact_hard3.wav"
bloodysounds[4] = "physics/flesh/flesh_squishy_impact_hard4.wav"

Here’s PART of the entire function:


function EntityTakeDamage( ent, dmginfo )

     if ent:IsValid() then

         local entpos = ent:GetPos()
		 local pos = dmginfo:GetDamagePosition()
	     local entmodel = ent:GetModel()
		 local entang = ent:GetAngles()
		 local direction = dmginfo:GetDamageForce()
		 local infl = dmginfo:GetInflictor()
	local att = dmginfo:GetAttacker()
	local amount = dmginfo:GetDamage()
		 
	     if (ent:GetClass() == "prop_ragdoll") or ent:IsNPC() then

             for k, model in pairs(goodmodel) do
		 
	             if string.find(entmodel,model) ~= nil then

					 -- First, when we get damaged by bullets!
					 if (dmginfo:IsDamageType(DMG_FALL) or dmginfo:IsDamageType(DMG_CRUSH)) then
						 
					     if (amount >= SlapDamage ) then
						 
						     ParticleEffect("blood_impact_red_01",pos,Angle(0,0,0),nil)
					         sound.Play( table.Random(bloodysounds), pos, 165, 100 )
							 
						 end
						 
						 if (amount >= GetConVar("g_explosiondamage"):GetInt() ) then
						 
						     ParticleEffect("blood_explosion",pos,Angle(0,0,0),nil)
						     Gib(ent,pos,ExplosionGibAmount,ExplosionForce,direction)
					 	     ent:Remove()
							 
					     end
					 end
					 
                     if (dmginfo:IsBulletDamage()) then
					 
                         local pos = dmginfo:GetDamagePosition()
	                     local entmodel = ent:GetModel()
						 
						 if (amount < HeavyDamage) then 
						 
						     ParticleEffect("blood_impact_soft",pos,Angle(0,0,0),nil)
							 
						 end
						 
                         if (amount >= HeavyDamage) then
							 
						     sound.Play( table.Random(bloodysounds), vPos, 75, 165, 100 )
				             ParticleEffect("blood_impact_hard",pos,Angle(0,0,0),nil)
						     Gib(ent,pos,SmallGibAmount,GibForce,direction)
		
	                     end		 
					 end