Trying to weld an entity to another entity.

I want to weld the top entity to the bottom entity with lua.
Does anyone know what I’m doing wrong?

Making a picture of the code is a very bad idea. Do you expect us to retype it to test it?

You haven’t told us what the problem is

Assuming the rotating blade at the top does not weld and either falls off or stays in midair?

Right, it simply doesn’t weld.

The highlighted part in the picture is what I’m working on. When I spawn the entity the top will fall off and there are no errors. Here’s the link to the wiki, http://wiki.garrysmod.com/page/constraint/Weld

The code for the init.lua




AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")

function ENT:Initialize()

	self:SetModel( "models/props_c17/lampShade001a.mdl" )
	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS )

	local phys = self:GetPhysicsObject()
	if (phys:IsValid()) then
	phys:SetMass( 50 )
	phys:Wake()
	end

	local ent = ents.Create( "turret_gun" )

	if (  !IsValid( ent ) ) then return end
	ent:SetPos( self:GetPos() + Vector(0,0,5) )
	ent:Spawn()
	
	constraint.Weld( self, ent, 0, 0, 0, false, false )
	
end



Maybe constraints are removed after entity initialization? Try applying this after initialization is complete, with a manually called function.

I’d say your entity isn’t valid until next frame.

local weld = constraint.Weld( self, ent, 0, 0, 0, false, false )
print( IsValid( weld ), type( weld ) )

try this:
timer.Simple( 0, function() if IsValid( ent ) && IsValid( self ) then constraint.Weld( self, ent, 0, 0, 0, false, false ) end end )