Prop spawning.

I want to make a function for my swep that creates a wood box that is frozen and collides with the player. Here is what I have.

[lua]

function SWEP:PrimaryAttack()

self.Weapon:SetNextPrimaryFire( CurTime() + 0.1 )

self:EmitSound( ShootSound )
self:ShootEffects( self )


if (!SERVER) then return end

local Forward = self.Owner:EyeAngles():Forward()

local ent = ents.Create( "prop_physics" )
if ( ValidEntity( ent ) ) then
		
		ent:SetModel("models/props_junk/wood_crate001a.mdl")
		ent:SetAngles( self.Owner:EyeAngles() )
		ent:SetMoveType(MOVETYPE_NONE)
		ent:SetSolid( SOLID_VPHYSICS )
		ent:SetPos( self.Owner:GetShootPos() + Forward * 50 )
	ent:Spawn()
	
end

ent:SetOwner( self.Owner )

end

[/lua]

This creates the box, but I do not collide with the box, nor does my physics gun beam. Also I want the box to be frozen and not move, but mine move. Please Help.

the problem is your using setowner do not use this.

Thank You! :smiley:

That worked but two things.

1.) Should I set the owner, is there a different way?

2.) I need the props to freeze the moment they spawn and stay frozen.

[editline]01:29AM[/editline]

Nevermind. I found the solution. I was telling the prop to freeze before it was spawned. Changing the order fixed it.

No there’s not really a reason to set the owner unless your doing it for a specific reason that your aware in the function of SetOwner(). Gmod, or your admin addon already handles who the prop actually belongs to whenever you spawn it.

If its coming from a swep does it handle it?

ent:SetNWEntity(“owner” , player)

Should work with most prop protection systems.