Part0 of weld is being reset after weapon in unequipped

Hello devform its me again, i am working on my Tactical Attachment System from this post : Tactical Attachments system. the problem that is happening is that after the weapon is unequipped the part0 of the weld is being reset
Line of code that handles welding

function ListHandler.AddedAttachment(attachmentButton: ImageButton, attachmentFolder: string, attachmentType:Part, gunAttachmentList:ModuleScript, attachmentTabel: string , wep:Model, weldObject:string, attachPoints: Folder, playerWep)
	attachmentButton.MouseButton1Click:Connect(function()
		if attachmentType.Name == attachmentButton.Name then
			local attachment = attachmentType:Clone()
			local attachment_ = attachment:Clone()
			if table.find(gunAttachmentList.attachments[attachmentTabel], attachment.Name) then
				print(attachmentType.Name .. ": Added to weapon")
				
				--loop through wepaon model
				for i, child in pairs(wep[attachmentFolder]:GetChildren()) do
					if i == 1 then
						child:Destroy()
					end
				end
				
				for i, child in pairs(playerWep[attachmentFolder]:GetChildren()) do
					if i == 1 then
						child:Destroy()
					end
				end
				
				--parent attachmet
				attachment.Parent = wep[attachmentFolder]
				attachment_.Parent = playerWep[attachmentFolder]
				--weld attachment
				attachment.weld.Part0 = attachPoints[weldObject]
				attachment_.weld.Part0 = attachPoints[weldObject]
				
				attachment.Position = attachPoints[weldObject].Position
				attachment_.Position = attachPoints[weldObject].Position
			end
		end
	end)
end

Any reason why you’re not setting the Part1 property of each weld instance?

1 Like

sorry for not getting back to you i thought this post died, the part1 property of the weld was preset

hey i found my solution since all the parts of the weapon were being cloned and parented to the viewmodel it would take some time for the attachment points folder to load which meant there was no part for the weld.Part0 property, to fix this is used WaitForChild() :wink: