Physics Object NULL or not of right type.

Hey i have this code:
[lua]
local Forward = self.Owner:EyeAngles():Forward()

local ent = ents.Create( "prop_physics" )
if ( ValidEntity( ent ) ) then
	local phys = ent:GetPhysicsObject()
		ent:SetModel("models/props_c17/oildrum001.mdl")//"models/Weapons/w_bugbait.mdl")
		ent:SetPos( self.Owner:GetShootPos() + Forward * 32 )
		ent:SetAngles( self.Owner:EyeAngles() )
	ent:Spawn()
	
	phys:Wake() -- line 64
	phys:SetVelocity( Forward * 500)

[/lua]

but iam getting this error:



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


any idea’s? I origionally thought i was because i was using bugbait as the model and that may not have a physics object but after changing it to a barrel (seen above) i know it must be the code, but i cannot see what is wrong with it. Any idea’s?

Try setting the model and spawning it before you get the physics object.

Do it after setting the model, and you may also need to call Activate.

lol works perfectly. This always happens with my questions. I miss out something so effing obvious.

Also clients don’t get physics objects. Just noting since it’s in shared.

it is in a server only part of the code.