Need help on fixing an error for a swep I am making

I need some help here as I am somewhat new to lua. I am making a scripted weapon that attaches a physics_cannister entity into an object using the manhack gun as a base, but I get this error when I spawn:


ERROR: Trying to derive entity physics_cannister from non existant entity nil!

Which means I can’t spawn the cannister, and if I try to use the primary function, it gives me this error:


ERROR: Trying to derive entity physics_cannister from non existant entity nil!
Error: Tried to make a SENT (physics_cannister) but the 'Type' (phys) was invalid!
[ERROR] lua/weapons/cannister_welder.lua:76: attempt to call method 'SetPos' (a nil value)
  1. unknown - lua/weapons/cannister_welder.lua:76

Here’s the mentioned line:


ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * 1 )

Thanks.

You code for physics_cannister is invalid.

So how would I implement it the right way? Do I have to make a scripted entity based off physics_cannister?

Show the code how you spawn it.

Oh, here it is:


local ent = ents.Create( "physics_cannister" )
	local ent = ents.FindByModel( "models/props_c17/canister01a.mdl" )
	ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * 1 )
	ent:SetAngles( tr.HitNormal:Angle() )
	ent:Spawn()

Wtf is local ent = ents.FindByModel( “models/props_c17/canister01a.mdl” )
and why do you have it there?

I thought it would set the model for the physics_cannister entity, whoops.

ent:SetModel( “models/props_c17/canister01a.mdl” )

It worked!

Now I feel like a dumbass, but thanks for your help.