Swep problem

Ok, making this swep…

pGrenade:GetPhysicsObject():SetVelocity( vecThrow );

gets this error

weapons/weapon_football/shared.lua:103: Tried to use invalid object (type IPhysicsObject) (Object was NULL or not of the right type)

anyone know how to fix it? thnx.

pGrenade:GetPhysicsObject() is not valid. Do something like

local phys = pGrenade:GetPhysicsObject()
if not IsValid(phys) then return end

Before your whatever you’re doing.

weapons/weapon_football/shared.lua:93: attempt to index global ‘pGrenade’ (a nil value)

That code u gave me is the error =/


Ok, I fixed all the errors. BUT. now when i left click it just looses ammo. doesn’t throw anything. add me on steam D:

We’d need to see more code, say the rest of your primary attack function, before we can really find out where the problem is.

-removed pastebin link… dont want noobs copying.- ill pm it to you guys.

Entoros’ lines quit out of the function if it’s not a valid physics object. Since you’re calling them before the entity is fully initialised, it makes sense that its physics object isn’t fully initialised either. Try moving the lines to after your ent:Activate() or taking them out, and seeing what happens (tell us which one you did).

Also you’re not at risk of your SWEP being copied - I Googled its base (swep_frag) and what you’re making is pretty much an edit of that. Without wanting to sound blunt you’re the one copying code and altering it.

By the way, the pastebin can be found on google


Please use more descriptive thread titles.



Ok , when I shoot like i said up top it just looses ammo. heres the pastebin’s.

SWEP: http://pastebin.com/6XkTfci6

SENT: http://pastebin.com/D894Kd8N