Few errors driving me insane.

Hey.

Ok for the past 2 hours i have been trying to fix every possible error regarding my falling/swimming event sweps. No matter how much isvalids i shove in the errors still appear.

[ERROR] lua/weapons/event_falling/shared.lua:137: Tried to use a NULL entity!

  1. GetVelocity - [C]:-1
  2. unknown - lua/weapons/event_falling/shared.lua:137

Line 136 - 140
[lua]
if vModel:IsValid() then
local vel = player:GetVelocity().z
//print(vel) --Debug stuff, don’t touch it it will spam your console.
vModel:SetPlaybackRate(1+vel/10000)
end
[/lua]

Also i’m trying to get a sound to loop when the sweps are deployed. At the beggining of the think hook i put:
[lua]
WaterLoop = CreateSound(self,“ambient/water/underwater.wav”)
WaterLoop:Play()
[/lua]
and then on the holster of the swep i put
WaterLoop:Stop()

But this pops up and the sound keeps playing. THis is annoying because it also does that after dieing and the only way to stop the looping sound is to use stopsound. This is the error:
[ERROR] lua/weapons/event_swimming/shared.lua:43: attempt to index global ‘WaterLoop’ (a nil value)

  1. unknown - lua/weapons/event_swimming/shared.lua:43
  2. SelectWeapon - [C]:-1
    3. unknown - lua/autorun/buu_base_scripts.lua:273
    4. unknown - lua/includes/modules/concommand.lua:69

This is everything in my hoster function:
[lua]
function SWEP:Holster()
local player = self:GetOwner()
WaterLoop:Stop()
if player:WaterLevel() >= 2 then
return false
end

return true

end
[/lua]
Thanks!

Don’t use Entity method IsValid, use Global IsValid.

vModel:IsValid() is giving you an error because there isn’t always a valid vModel. So sometimes you’re script is running a command that would look something like nil:IsValid(). IsValid(vModel) will do what you want.

Hmm I think using SWEP:Initialize() would help your second issue, but I’m unsure of that one. Try testing it out though. If you added me on steam/send me a PM I could look more into it.

[lua]
function SWEP:Initialize()
WaterLoop = CreateSound(self,“ambient/water/underwater.wav”)
end
[/lua]

Then place your play and stop according to how you want it used.

I tried that but it breaks it.

Before i add the isvalid:

[ERROR] lua/weapons/event_falling/shared.lua:117: Tried to use a NULL entity!

  1. GetVelocity - [C]:-1
  2. unknown - lua/weapons/event_falling/shared.lua:117
    Line 117 is this:
    local vel = player:GetVelocity().z

After i add a IsValid(self:GetOwner()) check

[ERROR] lua/weapons/event_falling/shared.lua:120: attempt to perform arithmetic on global ‘vel’ (a nil value)

  1. unknown - lua/weapons/event_falling/shared.lua:120

Line 120 is:
self.Owner:ViewPunch(Angle(math.random(-0.1+vel/10000,0.1+vel/10000),math.random(-0.1+vel/10000,0.1+vel/10000),math.random(-0.1+vel/10000,0.1+vel/10000)))

[editline]10th June 2014[/editline]

I tried putting it in the Initialize function but that didn’t solve anything.
I haven’t gotten the vmodel error yet, it seems random.

Ill add you tomorrow as its late here.

Try making a script that will print out the value of IsValid(vModel)
You’ll either get true or false, it should not break the script.

Your issue may be because of the way you’re using your variable “vel” can you show a few more lines around that one section? Could you also just add indicate lines 117 and 120?

Do you mind sending me a your script? I’ve got an idea of your errors (try declaring your variable earlier)

OK i tried sending SaintSin6 a invite but he wont reply. I guess that i will paste the code here and you guys can help me out:

Falling Hands:

Swimming Hands:

So for reference i get this error everytime i hit the ground:

And sometimes i get errors saying that the Fallloop / waterloop is a nil value, meaning when i respawn the sound keeps playing.